(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…