-
Notifications
You must be signed in to change notification settings - Fork 270
/
db_external_file_test.go
57 lines (46 loc) · 1.41 KB
/
db_external_file_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
55
56
57
package gorocksdb
import (
"io/ioutil"
"os"
"testing"
"github.com/facebookgo/ensure"
)
func TestExternalFile(t *testing.T) {
db := newTestDB(t, "TestDBExternalFile", nil)
defer db.Close()
envOpts := NewDefaultEnvOptions()
opts := NewDefaultOptions()
w := NewSSTFileWriter(envOpts, opts)
defer w.Destroy()
filePath, err := ioutil.TempFile("", "sst-file-test")
ensure.Nil(t, err)
defer os.Remove(filePath.Name())
err = w.Open(filePath.Name())
ensure.Nil(t, err)
err = w.Add([]byte("aaa"), []byte("aaaValue"))
ensure.Nil(t, err)
err = w.Add([]byte("bbb"), []byte("bbbValue"))
ensure.Nil(t, err)
err = w.Add([]byte("ccc"), []byte("cccValue"))
ensure.Nil(t, err)
err = w.Add([]byte("ddd"), []byte("dddValue"))
ensure.Nil(t, err)
err = w.Finish()
ensure.Nil(t, err)
ingestOpts := NewDefaultIngestExternalFileOptions()
err = db.IngestExternalFile([]string{filePath.Name()}, ingestOpts)
ensure.Nil(t, err)
readOpts := NewDefaultReadOptions()
v1, err := db.Get(readOpts, []byte("aaa"))
ensure.Nil(t, err)
ensure.DeepEqual(t, v1.Data(), []byte("aaaValue"))
v2, err := db.Get(readOpts, []byte("bbb"))
ensure.Nil(t, err)
ensure.DeepEqual(t, v2.Data(), []byte("bbbValue"))
v3, err := db.Get(readOpts, []byte("ccc"))
ensure.Nil(t, err)
ensure.DeepEqual(t, v3.Data(), []byte("cccValue"))
v4, err := db.Get(readOpts, []byte("ddd"))
ensure.Nil(t, err)
ensure.DeepEqual(t, v4.Data(), []byte("dddValue"))
}