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