forked from linxGnu/grocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice_transform_test.go
57 lines (45 loc) · 1.48 KB
/
slice_transform_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 grocksdb
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestSliceTransform(t *testing.T) {
t.Parallel()
db := newTestDB(t, func(opts *Options) {
opts.SetPrefixExtractor(&testSliceTransform{})
})
defer db.Close()
wo := NewDefaultWriteOptions()
require.Nil(t, db.Put(wo, []byte("foo1"), []byte("foo")))
require.Nil(t, db.Put(wo, []byte("foo2"), []byte("foo")))
require.Nil(t, db.Put(wo, []byte("bar1"), []byte("bar")))
iter := db.NewIterator(NewDefaultReadOptions())
defer iter.Close()
prefix := []byte("foo")
numFound := 0
for iter.Seek(prefix); iter.ValidForPrefix(prefix); iter.Next() {
numFound++
}
require.Nil(t, iter.Err())
require.EqualValues(t, numFound, 2)
}
func TestFixedPrefixTransformOpen(t *testing.T) {
t.Parallel()
db := newTestDB(t, func(opts *Options) {
opts.SetPrefixExtractor(NewFixedPrefixTransform(3))
})
defer db.Close()
}
func TestNewNoopPrefixTransform(t *testing.T) {
t.Parallel()
db := newTestDB(t, func(opts *Options) {
opts.SetPrefixExtractor(NewNoopPrefixTransform())
})
defer db.Close()
}
type testSliceTransform struct{}
func (st *testSliceTransform) Name() string { return "grocksdb.test" }
func (st *testSliceTransform) Transform(src []byte) []byte { return src[0:3] }
func (st *testSliceTransform) InDomain(src []byte) bool { return len(src) >= 3 }
func (st *testSliceTransform) InRange(src []byte) bool { return len(src) == 3 }
func (st *testSliceTransform) Destroy() {}