forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memdopmap_test.go
128 lines (116 loc) · 3.14 KB
/
memdopmap_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package gocbcore
import (
"github.com/couchbase/gocbcore/v10/memd"
)
func (suite *StandardTestSuite) TestOpMap() {
rd := newMemdOpMap()
testOp1 := &memdQRequest{
Packet: memd.Packet{},
}
testOp2 := &memdQRequest{
Packet: memd.Packet{},
}
testOp3 := &memdQRequest{
Packet: memd.Packet{},
Persistent: true,
}
// Single Remove
rd.Add(testOp1)
if rd.Remove(testOp1) != true {
suite.T().Fatalf("The op should be there")
}
if rd.Remove(testOp1) != false {
suite.T().Fatalf("There should be nothing to remove")
}
// Single opaque remove
rd.Add(testOp1)
if rd.FindAndMaybeRemove(testOp1.Opaque, false) != testOp1 {
suite.T().Fatalf("The op should have been found")
}
if rd.FindAndMaybeRemove(testOp1.Opaque, false) != nil {
suite.T().Fatalf("The op should not have been there")
}
// In order remove
rd.Add(testOp1)
rd.Add(testOp2)
if rd.Remove(testOp1) != true {
suite.T().Fatalf("The op should be there")
}
if rd.Remove(testOp2) != true {
suite.T().Fatalf("The op should be there")
}
if rd.Remove(testOp1) != false {
suite.T().Fatalf("There should be nothing to remove")
}
if rd.Remove(testOp2) != false {
suite.T().Fatalf("There should be nothing to remove")
}
// Out of order remove
rd.Add(testOp1)
rd.Add(testOp2)
if rd.Remove(testOp2) != true {
suite.T().Fatalf("The op should be there")
}
if rd.Remove(testOp1) != true {
suite.T().Fatalf("The op should be there")
}
if rd.Remove(testOp2) != false {
suite.T().Fatalf("There should be nothing to remove")
}
if rd.Remove(testOp1) != false {
suite.T().Fatalf("There should be nothing to remove")
}
// In order opaque remove
rd.Add(testOp1)
rd.Add(testOp2)
if rd.FindAndMaybeRemove(testOp1.Opaque, false) != testOp1 {
suite.T().Fatalf("The op should have been found")
}
if rd.FindAndMaybeRemove(testOp2.Opaque, false) != testOp2 {
suite.T().Fatalf("The op should have been found")
}
if rd.FindAndMaybeRemove(testOp1.Opaque, false) != nil {
suite.T().Fatalf("The op should not have been there")
}
if rd.FindAndMaybeRemove(testOp2.Opaque, false) != nil {
suite.T().Fatalf("The op should not have been there")
}
// Out of order opaque remove
rd.Add(testOp1)
rd.Add(testOp2)
if rd.FindAndMaybeRemove(testOp2.Opaque, false) != testOp2 {
suite.T().Fatalf("The op should have been found")
}
if rd.FindAndMaybeRemove(testOp1.Opaque, false) != testOp1 {
suite.T().Fatalf("The op should have been found")
}
if rd.FindAndMaybeRemove(testOp2.Opaque, false) != nil {
suite.T().Fatalf("The op should not have been there")
}
if rd.FindAndMaybeRemove(testOp1.Opaque, false) != nil {
suite.T().Fatalf("The op should not have been there")
}
rd.Add(testOp3)
if rd.FindAndMaybeRemove(testOp3.Opaque, true) != testOp3 {
suite.T().Fatalf("The op should have been found")
}
if rd.FindAndMaybeRemove(testOp3.Opaque, true) != nil {
suite.T().Fatalf("The op should not have been there")
}
// Drain
rd.Add(testOp2)
rd.Add(testOp1)
found1 := 0
found2 := 0
rd.Drain(func(op *memdQRequest) {
if op == testOp1 {
found1++
}
if op == testOp2 {
found2++
}
})
if found1 != 1 || found2 != 1 {
suite.T().Fatalf("Drain behaved incorrected")
}
}