func TestSplit2(t *testing.T) { storagePath := "split2Bitcask" os.RemoveAll(storagePath) opts := &Options{ MaxFileSize: 2, } bc, err := Open(storagePath, opts) assert.Nil(t, err) testKey := []byte("Foo") value := []byte("Bar") bc.Put(testKey, value) v, err := bc.Get(testKey) assert.Nil(t, err) assert.Equal(t, v, value) logger.Info("==============================") time.Sleep(time.Second * 2) // cause split file value = []byte("Apple") bc.Put(testKey, value) v, err = bc.Get(testKey) assert.Nil(t, err) assert.Equal(t, v, value) bc.Close() }
func TestBitCask(t *testing.T) { // clear dirty os.RemoveAll("testBitcask") b, err := Open("testBitcask", nil) logger.Info(err) assert.Nil(t, err) assert.NotNil(t, b) testKey := []byte("Foo") value := []byte("Bar") b.Put(testKey, value) v, err := b.Get(testKey) assert.Nil(t, err) logger.Info("value:", string(v)) assert.Equal(t, v, value) testKey = []byte("xiaoMing") value = []byte("abc") b.Put(testKey, value) v, err = b.Get(testKey) logger.Info("value:", string(v)) assert.Equal(t, v, value) // hintFile: value = []byte("ddddd") b.Put(testKey, value) v, err = b.Get(testKey) logger.Info("value:", string(v)) assert.Equal(t, v, value) b.Close() }
// rebuild file test func TestSplit1(t *testing.T) { storagePath := "split1Bitcask" os.RemoveAll(storagePath) bc, err := Open(storagePath, nil) assert.Nil(t, err) testKey := []byte("Foo") value := []byte("Bar") bc.Put(testKey, value) v, err := bc.Get(testKey) assert.Nil(t, err) assert.Equal(t, v, value) bc.Close() storagePath = "split1Bitcask" bc, err = Open(storagePath, nil) assert.Nil(t, err) testKey = []byte("Foo") value = []byte("Bar") bc.Put(testKey, value) v, err = bc.Get(testKey) assert.Nil(t, err) assert.Equal(t, v, value) bc.Close() }