-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch_test.go
70 lines (58 loc) · 1.17 KB
/
batch_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
package gorocks
import (
"bytes"
"testing"
)
func TestWriteBatchIterator(t *testing.T) {
wb := NewWriteBatch()
defer wb.Close()
it := wb.NewIterator()
if it.Next() {
t.Fatal("Next on empty iterator")
}
wb.Clear()
key := []byte("key")
value := []byte("value")
wb.Put(key, value)
it = wb.NewIterator()
it.Next()
record := it.Record()
if bytes.Compare(key, record.Key) != 0 {
t.Fatal("invalid key")
}
if bytes.Compare(value, record.Value) != 0 {
t.Fatal("invalid value")
}
if it.Error() != nil {
t.Fatal("Error on iterator")
}
wb.Clear()
for i := 0; i < 512; i++ {
key := make([]byte, i)
for j := 0; j < 512; j++ {
value := make([]byte, j)
wb.Put(key, value)
}
}
it = wb.NewIterator()
var count int
var kb, vb int
for count = 0; it.Next(); count++ {
rec := it.Record()
if rec.Type != RecordTypeValue {
t.Fatal("expected value record")
}
kb += len(rec.Key)
vb += len(rec.Value)
}
if count != 512*512 {
t.Fatal("records missing")
}
const n = 512 * (511 * 512 / 2)
if kb != n {
t.Fatalf("key bytes missing: expected %v, got %v", n, kb)
}
if vb != n {
t.Fatalf("value bytes missing: expected %v, got %v", n, vb)
}
}