(t *testing.T)
| 181 | } |
| 182 | |
| 183 | func TestConcurrentWrite(t *testing.T) { |
| 184 | runBadgerTest(t, nil, func(t *testing.T, db *DB) { |
| 185 | // Not a benchmark. Just a simple test for concurrent writes. |
| 186 | n := 20 |
| 187 | m := 500 |
| 188 | var wg sync.WaitGroup |
| 189 | for i := 0; i < n; i++ { |
| 190 | wg.Add(1) |
| 191 | go func(i int) { |
| 192 | defer wg.Done() |
| 193 | for j := 0; j < m; j++ { |
| 194 | txnSet(t, db, []byte(fmt.Sprintf("k%05d_%08d", i, j)), |
| 195 | []byte(fmt.Sprintf("v%05d_%08d", i, j)), byte(j%127)) |
| 196 | } |
| 197 | }(i) |
| 198 | } |
| 199 | wg.Wait() |
| 200 | |
| 201 | t.Log("Starting iteration") |
| 202 | |
| 203 | opt := IteratorOptions{} |
| 204 | opt.Reverse = false |
| 205 | opt.PrefetchSize = 10 |
| 206 | opt.PrefetchValues = true |
| 207 | |
| 208 | txn := db.NewTransaction(true) |
| 209 | it := txn.NewIterator(opt) |
| 210 | defer it.Close() |
| 211 | var i, j int |
| 212 | for it.Rewind(); it.Valid(); it.Next() { |
| 213 | item := it.Item() |
| 214 | k := item.Key() |
| 215 | if k == nil { |
| 216 | break // end of iteration. |
| 217 | } |
| 218 | |
| 219 | require.EqualValues(t, fmt.Sprintf("k%05d_%08d", i, j), string(k)) |
| 220 | v := getItemValue(t, item) |
| 221 | require.EqualValues(t, fmt.Sprintf("v%05d_%08d", i, j), string(v)) |
| 222 | require.Equal(t, item.UserMeta(), byte(j%127)) |
| 223 | j++ |
| 224 | if j == m { |
| 225 | i++ |
| 226 | j = 0 |
| 227 | } |
| 228 | } |
| 229 | require.EqualValues(t, n, i) |
| 230 | require.EqualValues(t, 0, j) |
| 231 | }) |
| 232 | } |
| 233 | |
| 234 | func TestGet(t *testing.T) { |
| 235 | test := func(t *testing.T, db *DB) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…