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

Function TestOpenStoreCollection

store_test.go:890–1099  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

888}
889
890func TestOpenStoreCollection(t *testing.T) {
891 tmpDir, _ := ioutil.TempDir("", "mossStore")
892 defer os.RemoveAll(tmpDir)
893
894 var mu sync.Mutex
895 counts := map[EventKind]int{}
896 eventWaiters := map[EventKind]chan bool{}
897
898 co := CollectionOptions{
899 MergeOperator: &MergeOperatorStringAppend{Sep: ":"},
900 OnEvent: func(event Event) {
901 mu.Lock()
902 counts[event.Kind]++
903 eventWaiter := eventWaiters[event.Kind]
904 mu.Unlock()
905 if eventWaiter != nil {
906 eventWaiter <- true
907 }
908 },
909 }
910
911 store, m, err := OpenStoreCollection(tmpDir, StoreOptions{
912 CollectionOptions: co,
913 }, StorePersistOptions{})
914 if err != nil || m == nil || store == nil {
915 t.Errorf("expected open empty store collection to work")
916 }
917
918 mirror := map[string]string{}
919
920 set1000 := true
921 delTens := true
922 updateOdds := true
923
924 numBatches := 0
925 for j := 0; j < 10; j++ {
926 if set1000 {
927 b, _ := m.NewBatch(0, 0)
928 for i := 0; i < 1000; i++ {
929 xs := fmt.Sprintf("%d", i)
930 x := []byte(xs)
931 b.Set(x, x)
932 mirror[xs] = xs
933 }
934 err = m.ExecuteBatch(b, WriteOptions{})
935 if err != nil {
936 t.Errorf("expected exec batch to work")
937 }
938 b.Close()
939
940 numBatches++
941 }
942
943 if delTens {
944 b, _ := m.NewBatch(0, 0)
945 for i := 0; i < 1000; i += 10 {
946 xs := fmt.Sprintf("%d", i)
947 x := []byte(xs)

Callers

nothing calls this directly

Calls 13

SetMethod · 0.95
CloseMethod · 0.95
DelMethod · 0.95
OpenStoreCollectionFunction · 0.85
ParseFNameSeqFunction · 0.85
NewBatchMethod · 0.65
ExecuteBatchMethod · 0.65
StatsMethod · 0.65
NameMethod · 0.65
SnapshotMethod · 0.65
StartIteratorMethod · 0.65
CurrentMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…