forked from linxGnu/grocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpoint_test.go
54 lines (43 loc) · 1.04 KB
/
checkpoint_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package grocksdb
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestCheckpoint(t *testing.T) {
t.Parallel()
dir := t.TempDir()
err := os.RemoveAll(dir)
require.Nil(t, err)
db := newTestDB(t, nil)
defer db.Close()
// insert keys
givenKeys := [][]byte{[]byte("key1"), []byte("key2"), []byte("key3")}
givenVal := []byte("val")
wo := NewDefaultWriteOptions()
for _, k := range givenKeys {
require.Nil(t, db.Put(wo, k, givenVal))
}
var dbCheck *DB
var checkpoint *Checkpoint
checkpoint, err = db.NewCheckpoint()
defer checkpoint.Destroy()
require.NotNil(t, checkpoint)
require.Nil(t, err)
err = checkpoint.CreateCheckpoint(dir, 0)
require.Nil(t, err)
opts := NewDefaultOptions()
opts.SetCreateIfMissing(true)
dbCheck, err = OpenDb(opts, dir)
require.Nil(t, err)
defer dbCheck.Close()
// test keys
var value *Slice
ro := NewDefaultReadOptions()
for _, k := range givenKeys {
value, err = dbCheck.Get(ro, k)
require.Nil(t, err)
require.EqualValues(t, value.Data(), givenVal)
value.Free()
}
}