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

Function TestIteratorMergeOps

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

Source from the content-addressed store, hash-verified

18)
19
20func TestIteratorMergeOps(t *testing.T) {
21 var mlock sync.Mutex
22
23 events := map[EventKind]int{}
24
25 mo := &MergeOperatorStringAppend{Sep: ":"}
26
27 m, err := NewCollection(CollectionOptions{
28 MergeOperator: mo,
29 OnEvent: func(e Event) {
30 mlock.Lock()
31 events[e.Kind]++
32 mlock.Unlock()
33 },
34 })
35 if err != nil || m == nil {
36 t.Errorf("expected moss")
37 }
38 mc := m.(*collection)
39
40 err = m.Start()
41 if err != nil {
42 t.Errorf("expected Start ok")
43 }
44
45 mergeVal := func(v string) {
46 b, err := m.NewBatch(0, 0)
47 if err != nil || b == nil {
48 t.Errorf("expected b ok")
49 }
50 b.Merge([]byte("a"), []byte(v))
51 err = m.ExecuteBatch(b, WriteOptions{})
52 if err != nil {
53 t.Errorf("expected execute batch ok")
54 }
55 }
56
57 mergeVal("A")
58 mergeVal("B")
59
60 mc.NotifyMerger("mergeAll", true)
61
62 checkVal := func(expected string) {
63 ss, err := m.Snapshot()
64 if err != nil {
65 t.Errorf("expected ss ok")
66 }
67 iter, err := ss.StartIterator(nil, nil, IteratorOptions{})
68 if err != nil || iter == nil {
69 t.Errorf("expected iter")
70 }
71 k, v, err := iter.Current()
72 if err != nil {
73 t.Errorf("expected current")
74 }
75 if string(k) != "a" {
76 t.Errorf("expected current key a")
77 }

Callers

nothing calls this directly

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…