-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaedb_test.go
86 lines (76 loc) · 1.67 KB
/
vaedb_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* User: coder.sdp@gmail.com
* Date: 2023/8/24
* Time: 12:00
*/
package vaedb
import (
"fmt"
"strconv"
"testing"
)
//t
var cnt = 100000
const keyPrefix = "test"
var db, _ = NewVaeDB(".")
func TestBigSet(t *testing.T) {
for i := 0; i < cnt; i++ {
k := keyPrefix + strconv.Itoa(i)
fmt.Println(db.Set(k, []byte(k+"tv")))
}
}
func TestBigGet(t *testing.T) {
for i := 0; i < cnt; i++ {
k := keyPrefix + strconv.Itoa(i)
v := string(db.Get(k))
if v != k+"tv" {
t.Errorf("err k:%s v%s", k, v)
}
}
}
func TestSetAndGet(t *testing.T) {
//set
t.Run("c_set", func(t *testing.T) {
t.Parallel()
for i := 0; i < cnt; i++ {
k := keyPrefix + strconv.Itoa(i)
db.Set(k, []byte(k+"tv"))
}
})
//get
t.Run("c_get", func(t *testing.T) {
t.Parallel()
for i := 0; i < cnt; i++ {
k := keyPrefix + strconv.Itoa(i)
v := string(db.Get(k))
if v != "" && v != k+"tv" {
t.Errorf("err k:%s v%s", k, v)
}
}
})
}
//get拦截器测试
func TestSetGetInterceptor(t *testing.T) {
getInter := func(chain *Chain) {
key := chain.Key
chain.Key = "test2"
t.Logf("获取到原key %s,并更改Key %s", key, chain.Key)
chain.Next()
t.Logf("获取到key %s,val %s", chain.Key, chain.Key)
}
db, _ = NewVaeDB(".", SetGetInterceptor(getInter))
db.Get(keyPrefix + "1")
}
//set拦截器测试
func TestSetSetInterceptor(t *testing.T) {
setInter := func(chain *Chain) {
key := chain.Key
chain.Key = "test2"
t.Logf("获取到原key %s,并更改Key %s", key, chain.Key)
chain.Next()
}
db, _ = NewVaeDB(".", SetSetInterceptor(setInter))
db.Set("test1", []byte("spe"))
t.Logf("获取 test1 %s", db.Get("test1"))
t.Logf("获取 test2 %s", db.Get("test2"))
}