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

Function testIteratorSingleMergeOp

iterator_test.go:230–307  ·  view source on GitHub ↗
(t *testing.T,
	mergeVals []string, expectVal string)

Source from the content-addressed store, hash-verified

228}
229
230func testIteratorSingleMergeOp(t *testing.T,
231 mergeVals []string, expectVal string) {
232 var mlock sync.Mutex
233
234 events := map[EventKind]int{}
235
236 mo := &MergeOperatorStringAppend{Sep: ":"}
237
238 m, err := NewCollection(CollectionOptions{
239 MergeOperator: mo,
240 OnEvent: func(e Event) {
241 mlock.Lock()
242 events[e.Kind]++
243 mlock.Unlock()
244 },
245 })
246 if err != nil || m == nil {
247 t.Errorf("expected moss")
248 }
249 mc := m.(*collection)
250
251 err = m.Start()
252 if err != nil {
253 t.Errorf("expected Start ok")
254 }
255
256 mergeVal := func(v string) {
257 b, err := m.NewBatch(0, 0)
258 if err != nil || b == nil {
259 t.Errorf("expected b ok")
260 }
261 b.Merge([]byte("a"), []byte(v))
262 err = m.ExecuteBatch(b, WriteOptions{})
263 if err != nil {
264 t.Errorf("expected execute batch ok")
265 }
266 }
267
268 for _, mv := range mergeVals {
269 mergeVal(mv)
270 }
271
272 mc.NotifyMerger("mergeAll", true)
273
274 checkVal := func(expected string) {
275 ss, err := m.Snapshot()
276 if err != nil {
277 t.Errorf("expected ss ok")
278 }
279 iter, err := ss.StartIterator(nil, nil, IteratorOptions{})
280 if err != nil || iter == nil {
281 t.Errorf("expected iter")
282 }
283 _, ok := iter.(*iteratorSingle)
284 if !ok {
285 t.Errorf("expected iteratorSingle")
286 }
287 k, v, err := iter.Current()

Callers 2

Calls 11

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…