---------------------------------------------------------------
(tmpDir string, items int, batches int)
| 61 | // --------------------------------------------------------------- |
| 62 | |
| 63 | func createStoreAndWriteNItems(tmpDir string, items int, |
| 64 | batches int) (s *Store, c Collection, ks [][]byte) { |
| 65 | |
| 66 | store, coll, err := OpenStoreCollection(tmpDir, |
| 67 | StoreOptions{}, |
| 68 | StorePersistOptions{}) |
| 69 | |
| 70 | if err != nil || store == nil { |
| 71 | panic("OpenStoreCollection() failed!") |
| 72 | } |
| 73 | |
| 74 | keys := make([][]byte, items) |
| 75 | |
| 76 | if batches > items { |
| 77 | batches = 1 |
| 78 | } |
| 79 | itemsPerBatch := items / batches |
| 80 | itemCount := 0 |
| 81 | |
| 82 | for i := 0; i < batches; i++ { |
| 83 | if itemsPerBatch > items-itemCount { |
| 84 | itemsPerBatch = items - itemCount |
| 85 | } |
| 86 | |
| 87 | if itemsPerBatch <= 0 { |
| 88 | break |
| 89 | } |
| 90 | |
| 91 | batch, err := coll.NewBatch(itemsPerBatch, itemsPerBatch*20) |
| 92 | if err != nil { |
| 93 | panic("NewBatch() failed!") |
| 94 | } |
| 95 | |
| 96 | for j := 0; j < itemsPerBatch; j++ { |
| 97 | k := []byte(fmt.Sprintf("key%d", i)) |
| 98 | v := []byte(fmt.Sprintf("val%d", i)) |
| 99 | itemCount++ |
| 100 | |
| 101 | batch.Set(k, v) |
| 102 | keys[j] = k |
| 103 | } |
| 104 | |
| 105 | err = coll.ExecuteBatch(batch, WriteOptions{}) |
| 106 | if err != nil { |
| 107 | panic("ExecuteBatch() failed!") |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return store, coll, keys |
| 112 | } |
no test coverage detected
searching dependent graphs…