forked from brahma-adshonor/gorr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_test.go
78 lines (57 loc) · 1.33 KB
/
storage_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
package gorr
import (
//"fmt"
"github.com/stretchr/testify/assert"
"os"
"runtime"
"testing"
)
func TestBoltDb(t *testing.T) {
db, err := NewBoltStorage("./r.test.data")
assert.Nil(t, err)
data := []byte("random value")
err1 := db.Put("miliao", data)
assert.Nil(t, err1)
d2, err2 := db.Get("miliao")
assert.Nil(t, err2)
assert.Equal(t, data, d2)
d3, err3 := db.Get("miliao2")
assert.Nil(t, d3)
assert.NotNil(t, err3)
data2 := []byte("random value222")
err4 := db.Put("miliao", data2)
assert.Nil(t, err4)
d4, err5 := db.Get("miliao")
assert.Nil(t, err5)
assert.Equal(t, data2, d4)
assert.NotEqual(t, data, d4)
db.Close()
runtime.GC()
*bolt_db_big_value_thresh = 1024
db, err = NewBoltStorage("./r.test.data")
assert.Nil(t, err)
defer func() {
for _, f := range db.AllFiles() {
os.Remove(f)
}
}()
d5, err6 := db.Get("miliao")
assert.Nil(t, err6)
runtime.GC()
assert.Equal(t, data2, d5)
assert.NotEqual(t, data, d5)
runtime.GC()
big_size := 2 * 1024 * 1024
big_value := make([]byte, 0, big_size)
for i := 0; i < big_size; i++ {
big_value = append(big_value, 'a')
}
err = db.Put("big_value", big_value)
assert.Nil(t, err)
runtime.GC()
d6, err7 := db.Get("big_value")
assert.Nil(t, err7)
assert.Equal(t, big_size, len(d6))
assert.Equal(t, big_value, d6)
assert.Equal(t, 2, len(db.AllFiles()))
}