MCPcopy Create free account
hub / github.com/couchbase/moss / TestIteratorMergeOps_MB19667

Function TestIteratorMergeOps_MB19667

iterator_test.go:116–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestIteratorMergeOps_MB19667(t *testing.T) {
117 // Need to arrange that...
118 // - stack dirty top = empty
119 // - stack dirty mid = [ various merge ops ]
120 // - stack dirty base = [ more merge ops ]
121 //
122 var mlock sync.Mutex
123
124 events := map[EventKind]int{}
125
126 var eventCh chan EventKind
127
128 mo := &MergeOperatorStringAppend{Sep: ":"}
129
130 m, err := NewCollection(CollectionOptions{
131 MergeOperator: mo,
132 OnEvent: func(e Event) {
133 mlock.Lock()
134 events[e.Kind]++
135 if eventCh != nil {
136 eventCh <- e.Kind
137 }
138 mlock.Unlock()
139 },
140 })
141 if err != nil || m == nil {
142 t.Errorf("expected moss")
143 }
144 mc := m.(*collection)
145
146 // Note that we haven't Start()'ed the collection yet, so it
147 // doesn't have any background goroutines runnning yet.
148
149 mergeVal := func(v string) {
150 b, err := m.NewBatch(0, 0)
151 if err != nil || b == nil {
152 t.Errorf("expected b ok")
153 }
154 b.Merge([]byte("k"), []byte(v))
155 err = m.ExecuteBatch(b, WriteOptions{})
156 if err != nil {
157 t.Errorf("expected execute batch ok")
158 }
159 b.Close()
160 }
161
162 mergeVal("A")
163 mergeVal("B")
164
165 // Pretend to be the merger, moving stack dirty top into base.
166 mc.m.Lock()
167 mc.stackDirtyBase = mc.stackDirtyTop
168 mc.stackDirtyTop = nil
169 mc.m.Unlock()
170
171 mergeVal("C")
172 mergeVal("D")
173

Callers

nothing calls this directly

Calls 12

NewBatchMethod · 0.95
MergeMethod · 0.95
ExecuteBatchMethod · 0.95
CloseMethod · 0.95
SnapshotMethod · 0.95
NewCollectionFunction · 0.85
NotifyMergerMethod · 0.80
GetMethod · 0.65
StartIteratorMethod · 0.65
CurrentMethod · 0.65
NextMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…