MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestMemWal_Write

Function TestMemWal_Write

kayak/wal/mem_wal_test.go:29–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestMemWal_Write(t *testing.T) {
30 Convey("test mem wal write", t, func() {
31 var p *MemWal
32 p = NewMemWal()
33
34 l1 := &kt.Log{
35 LogHeader: kt.LogHeader{
36 Index: 0,
37 Type: kt.LogPrepare,
38 },
39 Data: []byte("happy1"),
40 }
41
42 var err error
43 err = p.Write(l1)
44 So(err, ShouldBeNil)
45 So(p.logs, ShouldResemble, []*kt.Log{l1})
46 err = p.Write(l1)
47 So(err, ShouldNotBeNil)
48 So(p.revIndex, ShouldHaveLength, 1)
49 So(p.revIndex[l1.Index], ShouldEqual, 0)
50 So(p.offset, ShouldEqual, 1)
51
52 // test get
53 var l *kt.Log
54 l, err = p.Get(l1.Index)
55 So(err, ShouldBeNil)
56 So(l, ShouldResemble, l1)
57
58 _, err = p.Get(10000)
59 So(err, ShouldNotBeNil)
60
61 // test consecutive writes
62 l2 := &kt.Log{
63 LogHeader: kt.LogHeader{
64 Index: 1,
65 Type: kt.LogPrepare,
66 },
67 Data: []byte("happy2"),
68 }
69 err = p.Write(l2)
70 So(err, ShouldBeNil)
71 So(p.revIndex, ShouldHaveLength, 2)
72 So(p.revIndex[l2.Index], ShouldEqual, 1)
73 So(p.offset, ShouldEqual, 2)
74
75 // test not consecutive writes
76 l4 := &kt.Log{
77 LogHeader: kt.LogHeader{
78 Index: 3,
79 Type: kt.LogPrepare,
80 },
81 Data: []byte("happy3"),
82 }
83 err = p.Write(l4)
84 So(err, ShouldBeNil)
85 So(p.revIndex, ShouldHaveLength, 3)
86 So(p.revIndex[l4.Index], ShouldEqual, 2)

Callers

nothing calls this directly

Calls 5

WriteMethod · 0.95
GetMethod · 0.95
ReadMethod · 0.95
CloseMethod · 0.95
NewMemWalFunction · 0.85

Tested by

no test coverage detected