(t *testing.T, co CollectionOptions, spo StorePersistOptions)
| 619 | } |
| 620 | |
| 621 | func testStoreCompaction(t *testing.T, co CollectionOptions, |
| 622 | spo StorePersistOptions) { |
| 623 | tmpDir, _ := ioutil.TempDir("", "mossStore") |
| 624 | defer os.RemoveAll(tmpDir) |
| 625 | |
| 626 | co.MergeOperator = &MergeOperatorStringAppend{Sep: ":"} |
| 627 | |
| 628 | var mu sync.Mutex |
| 629 | counts := map[EventKind]int{} |
| 630 | |
| 631 | co.OnEvent = func(event Event) { |
| 632 | mu.Lock() |
| 633 | counts[event.Kind]++ |
| 634 | mu.Unlock() |
| 635 | } |
| 636 | |
| 637 | store, err := OpenStore(tmpDir, StoreOptions{ |
| 638 | CollectionOptions: co, |
| 639 | }) |
| 640 | if err != nil || store == nil { |
| 641 | t.Errorf("expected open empty store to work") |
| 642 | } |
| 643 | |
| 644 | ssInit, err := store.Snapshot() |
| 645 | if err != nil || ssInit == nil { |
| 646 | t.Errorf("expected ssInit") |
| 647 | } |
| 648 | |
| 649 | persistCh := make(chan struct{}) |
| 650 | |
| 651 | co2 := co |
| 652 | co2.LowerLevelInit = ssInit |
| 653 | co2.LowerLevelUpdate = func(higher Snapshot) (Snapshot, error) { |
| 654 | ss, errx := store.Persist(higher, spo) |
| 655 | persistCh <- struct{}{} |
| 656 | return ss, errx |
| 657 | } |
| 658 | |
| 659 | m, err := NewCollection(co2) |
| 660 | if err != nil || m == nil { |
| 661 | t.Errorf("expected moss") |
| 662 | } |
| 663 | |
| 664 | m.Start() |
| 665 | |
| 666 | mirror := map[string]string{} |
| 667 | |
| 668 | set1000 := true |
| 669 | delTens := true |
| 670 | updateOdds := true |
| 671 | |
| 672 | numBatches := 0 |
| 673 | for j := 0; j < 10; j++ { |
| 674 | if set1000 { |
| 675 | b, _ := m.NewBatch(0, 0) |
| 676 | for i := 0; i < 1000; i++ { |
| 677 | xs := fmt.Sprintf("%d", i) |
| 678 | x := []byte(xs) |
no test coverage detected
searching dependent graphs…