-
Notifications
You must be signed in to change notification settings - Fork 92
/
datalog_test.go
45 lines (35 loc) · 1.31 KB
/
datalog_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
package pogreb
import (
"testing"
"github.com/akrylysov/pogreb/internal/assert"
)
func (dl *datalog) segmentMetas() []segmentMeta {
var metas []segmentMeta
for _, seg := range dl.segmentsBySequenceID() {
metas = append(metas, *seg.meta)
}
return metas
}
func TestDatalog(t *testing.T) {
db, err := createTestDB(nil)
assert.Nil(t, err)
_, _, err = db.datalog.put([]byte{'1'}, []byte{'1'})
assert.Nil(t, err)
assert.Equal(t, &segmentMeta{PutRecords: 1}, db.datalog.segments[0].meta)
assert.Nil(t, db.datalog.segments[1])
sm := db.datalog.segmentsBySequenceID()
assert.Equal(t, []*segment{db.datalog.segments[0]}, sm)
// Writing to a full file swaps it.
db.datalog.segments[0].meta.Full = true
_, _, err = db.datalog.put([]byte{'1'}, []byte{'1'})
assert.Nil(t, err)
assert.Equal(t, &segmentMeta{PutRecords: 1, Full: true}, db.datalog.segments[0].meta)
assert.Equal(t, &segmentMeta{PutRecords: 1}, db.datalog.segments[1].meta)
sm = db.datalog.segmentsBySequenceID()
assert.Equal(t, []*segment{db.datalog.segments[0], db.datalog.segments[1]}, sm)
_, _, err = db.datalog.put([]byte{'1'}, []byte{'1'})
assert.Nil(t, err)
assert.Equal(t, &segmentMeta{PutRecords: 1, Full: true}, db.datalog.segments[0].meta)
assert.Equal(t, &segmentMeta{PutRecords: 2}, db.datalog.segments[1].meta)
assert.Nil(t, db.Close())
}