-
Notifications
You must be signed in to change notification settings - Fork 29
/
db_load_test.go
69 lines (59 loc) · 1.29 KB
/
db_load_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
package flashdb
import (
"fmt"
"os"
"testing"
"github.com/arriqaaq/aol"
"github.com/stretchr/testify/assert"
)
func makeLoadRecords(n int, db *FlashDB) {
for i := 1; i <= n; i++ {
key := fmt.Sprintf("key_%d", i)
member := fmt.Sprintf("member_%d", i)
value := fmt.Sprintf("value_%d", i)
db.Update(func(tx *Tx) error {
tx.HSet(key, member, value)
tx.SAdd(key, member)
tx.Set(key, member)
tx.ZAdd(key, 10.0, member)
return nil
})
}
}
func TestFlashDB_load(t *testing.T) {
db := getTestDB()
logPath := "tmp/"
l, err := aol.Open(logPath, nil)
if err != nil {
t.Fatal(err)
}
db.log = l
db.persist = true
defer os.RemoveAll("tmp/")
makeLoadRecords(10, db)
db.Close()
p, err := aol.Open(logPath, nil)
if err != nil {
t.Fatal(err)
}
db2 := getTestDB()
db2.log = p
err = db2.load()
assert.NoError(t, err)
for i := 1; i <= 10; i++ {
key := fmt.Sprintf("key_%d", i)
member := fmt.Sprintf("member_%d", i)
value := fmt.Sprintf("value_%d", i)
db2.View(func(tx *Tx) error {
assert.Equal(t, value, tx.HGet(key, member))
assert.True(t, tx.SIsMember(key, member))
val, err := tx.Get(key)
assert.NoError(t, err)
assert.Equal(t, member, val)
ok, score := tx.ZScore(key, member)
assert.True(t, ok)
assert.Equal(t, 10.0, score)
return nil
})
}
}