Beispiel #1
0
func TestResplit(t *testing.T) {
	ds, tmpDir := makeTestingDirectory(t)
	defer os.RemoveAll(tmpDir)
	defer ds.Close()

	ds.mu.Lock()
	ds.minSplitSize = 2
	ds.maxSplitSize = 8
	ds.mu.Unlock()

	const itemCount = 50

	for i := 0; i < itemCount; i++ {
		key := strconv.FormatInt(int64(i), 3)
		storetests.ShouldCAS(t, ds, key, store.AnyV, store.DataV([]byte(key)))

		ds.resplit()

		for j := 0; j < itemCount; j++ {
			key := strconv.FormatInt(int64(j), 3)
			if j <= i {
				storetests.ShouldGet(t, ds, key, []byte(key))
			} else {
				storetests.ShouldGetMiss(t, ds, key)
			}
		}

		checkSplitCountSizes(t, "insertion", tmpDir, 2, 8)
	}

	for i := 0; i < itemCount; i++ {
		key := strconv.FormatInt(int64(i), 3)
		storetests.ShouldCAS(t, ds, key, store.AnyV, store.MissingV)

		ds.resplit()

		for j := 0; j < itemCount; j++ {
			key := strconv.FormatInt(int64(j), 3)
			if j <= i {
				storetests.ShouldGetMiss(t, ds, key)
			} else {
				storetests.ShouldGet(t, ds, key, []byte(key))
			}
		}

		checkSplitCountSizes(t, "deletion", tmpDir, 2, 8)
	}
}
Beispiel #2
0
func TestMultiScrubRemovesWeirdChunks(t *testing.T) {
	_, multi, mocks, done := prepareMultiTest(t, 1, 1, 1)
	defer done()

	storetests.ShouldCAS(t, mocks[0], "a", store.MissingV, store.DataV([]byte("data")))
	multi.scrubAll()
	storetests.ShouldGetMiss(t, mocks[0], "a")
}
Beispiel #3
0
func TestDirectoryCorruption(t *testing.T) {
	ds, tmpDir := makeTestingDirectory(t)
	defer os.RemoveAll(tmpDir)
	defer ds.Close()

	storetests.ShouldCAS(t, ds, "hello", store.AnyV, store.DataV([]byte("world")))
	shouldHashcheck(t, ds, 1, 0)
	shouldCorrupt(t, filepath.Join(tmpDir, "data", "1", "aGVsbG8="))
	storetests.ShouldGetError(t, ds, "hello", ErrCorruptObject)
	storetests.ShouldGetMiss(t, ds, "hello")
	shouldFileExist(t, filepath.Join(tmpDir, "quarantine", "aGVsbG8="))

	storetests.ShouldCAS(t, ds, "other", store.AnyV, store.DataV([]byte("werld")))
	shouldHashcheck(t, ds, 1, 0)
	shouldCorrupt(t, filepath.Join(tmpDir, "data", "1", "b3RoZXI="))
	shouldHashcheck(t, ds, 0, 1)
	storetests.ShouldGetMiss(t, ds, "other")
	shouldHashcheck(t, ds, 0, 0)
	shouldFileExist(t, filepath.Join(tmpDir, "quarantine", "b3RoZXI="))
}