-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathrecord_test.go
62 lines (54 loc) · 1.24 KB
/
record_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
package flashdb
import (
"fmt"
"os"
"testing"
"github.com/arriqaaq/aol"
"github.com/stretchr/testify/assert"
)
func makeRecords(n int) []*record {
rec := make([]*record, 0, n)
for i := 1; i <= n; i++ {
key := fmt.Sprintf("key_%d", i)
value := fmt.Sprintf("value_%d", i)
member := fmt.Sprintf("member_%d", i)
rec = append(rec, newRecordWithValue([]byte(key), []byte(member), []byte(value), ZSetRecord, ZSetZAdd))
}
return rec
}
func TestFlashDB_AOL(t *testing.T) {
logPath := "tmp/"
l, err := aol.Open(logPath, nil)
if err != nil {
t.Fatal(err)
}
defer l.Close()
defer os.RemoveAll(logPath)
recs := makeRecords(100)
for _, r := range recs {
data, err := r.encode()
assert.NoError(t, err)
l.Write(data)
}
var lastRecord *record
segs := l.Segments()
for i := 1; i <= segs; i++ {
j := 0
for {
data, err := l.Read(uint64(i), uint64(j))
if err != nil {
if err == aol.ErrEOF {
break
}
t.Fatalf("expected %v, got %v", nil, err)
}
res, err := decode(data)
assert.NoError(t, err)
lastRecord = res
j++
}
}
assert.Equal(t, "key_100", string(lastRecord.meta.key))
assert.Equal(t, "member_100", string(lastRecord.meta.member))
assert.Equal(t, "value_100", string(lastRecord.meta.value))
}