forked from nutsdb/nutsdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
120 lines (101 loc) · 2.24 KB
/
options_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package nutsdb
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWithNodeNum(t *testing.T) {
InitOpt("", true)
db, err := Open(
opt,
WithNodeNum(1011),
)
assert.NoError(t, err)
assert.Equal(t, int64(1011), db.opt.NodeNum)
err = db.Close()
assert.NoError(t, err)
}
func TestWithMaxBatchCount(t *testing.T) {
InitOpt("", true)
db, err := Open(
opt,
WithMaxBatchCount(10),
)
assert.NoError(t, err)
assert.Equal(t, int64(10), db.getMaxBatchCount())
err = db.Close()
assert.NoError(t, err)
}
func TestWithMaxBatchSize(t *testing.T) {
InitOpt("", true)
db, err := Open(
opt,
WithMaxBatchSize(100),
)
assert.NoError(t, err)
assert.Equal(t, int64(100), db.getMaxBatchSize())
err = db.Close()
assert.NoError(t, err)
}
func TestWithRWMode(t *testing.T) {
db, err = Open(DefaultOptions,
WithDir("/tmp/nutsdb"),
WithRWMode(MMap),
)
assert.NoError(t, err)
assert.Equal(t, db.opt.RWMode, MMap)
err = db.Close()
assert.NoError(t, err)
}
func TestWithSyncEnable(t *testing.T) {
db, err = Open(DefaultOptions,
WithDir("/tmp/nutsdb"),
WithSyncEnable(false),
)
assert.NoError(t, err)
assert.False(t, db.opt.SyncEnable)
err = db.Close()
assert.NoError(t, err)
}
func TestWithMaxFdNumsInCache(t *testing.T) {
db, err = Open(DefaultOptions,
WithDir("/tmp/nutsdb"),
WithMaxFdNumsInCache(100),
)
assert.NoError(t, err)
assert.Equal(t, db.opt.MaxFdNumsInCache, 100)
err = db.Close()
assert.NoError(t, err)
}
func TestWithCleanFdsCacheThreshold(t *testing.T) {
db, err = Open(DefaultOptions,
WithDir("/tmp/nutsdb"),
WithCleanFdsCacheThreshold(0.5),
)
assert.NoError(t, err)
assert.Equal(t, db.opt.CleanFdsCacheThreshold, 0.5)
err = db.Close()
assert.NoError(t, err)
}
func TestWithErrorHandler(t *testing.T) {
db, err = Open(DefaultOptions,
WithDir("/tmp/nutsdb"),
WithErrorHandler(ErrorHandlerFunc(func(err error) {
})),
)
assert.NoError(t, err)
assert.NotNil(t, db.opt.ErrorHandler)
err = db.Close()
assert.NoError(t, err)
}
func TestWithLessFunc(t *testing.T) {
db, err = Open(DefaultOptions,
WithDir("/tmp/nutsdb"),
WithLessFunc(func(l, r string) bool {
return len(l) < len(r)
}),
)
assert.NoError(t, err)
assert.NotNil(t, db.opt.LessFunc)
err = db.Close()
assert.NoError(t, err)
}