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

Function openStoreAndWriteNItems

store_test.go:1745–1840  ·  view source on GitHub ↗
(t *testing.T, tmpDir string,
	n int, numBatches int, readOnly bool)

Source from the content-addressed store, hash-verified

1743}
1744
1745func openStoreAndWriteNItems(t *testing.T, tmpDir string,
1746 n int, numBatches int, readOnly bool) (s *Store, c Collection) {
1747 var store *Store
1748 var coll Collection
1749 var err error
1750
1751 var m sync.Mutex
1752 var waitingForCleanCh chan struct{}
1753
1754 var co CollectionOptions
1755
1756 co = CollectionOptions{
1757 OnEvent: func(event Event) {
1758 if event.Kind == EventKindPersisterProgress {
1759 var stats *CollectionStats
1760 stats, err = coll.Stats()
1761 if err == nil && stats.CurDirtyOps <= 0 &&
1762 stats.CurDirtyBytes <= 0 && stats.CurDirtySegments <= 0 {
1763 m.Lock()
1764 if waitingForCleanCh != nil {
1765 waitingForCleanCh <- struct{}{}
1766 waitingForCleanCh = nil
1767 }
1768 m.Unlock()
1769 }
1770 }
1771 },
1772 ReadOnly: readOnly,
1773 }
1774
1775 ch := make(chan struct{}, 1)
1776
1777 store, coll, err = OpenStoreCollection(tmpDir,
1778 StoreOptions{CollectionOptions: co},
1779 StorePersistOptions{})
1780
1781 if err != nil || store == nil {
1782 t.Errorf("Moss-OpenStoreCollection failed, err: %v", err)
1783 }
1784
1785 if n <= numBatches {
1786 numBatches = 1
1787 }
1788
1789 itemsPerBatch := n / numBatches
1790 itemCount := 0
1791
1792 for bi := 0; bi < numBatches; bi++ {
1793 if itemsPerBatch > n-itemCount {
1794 itemsPerBatch = n - itemCount
1795 }
1796
1797 if itemsPerBatch <= 0 {
1798 break
1799 }
1800
1801 batch, err := coll.NewBatch(itemsPerBatch, itemsPerBatch*15)
1802 if err != nil {

Callers 2

TestStoreReadOnlyOptionFunction · 0.85
TestStoreCollHistogramsFunction · 0.85

Calls 8

StatsMethod · 0.95
NewBatchMethod · 0.95
SetMethod · 0.95
ExecuteBatchMethod · 0.95
SnapshotMethod · 0.95
PersistMethod · 0.95
OpenStoreCollectionFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…