MCPcopy
hub / github.com/dgraph-io/badger / TestConcurrentWrite

Function TestConcurrentWrite

db_test.go:183–232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

181}
182
183func 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
234func TestGet(t *testing.T) {
235 test := func(t *testing.T, db *DB) {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
runBadgerTestFunction · 0.85
txnSetFunction · 0.85
getItemValueFunction · 0.85
NewTransactionMethod · 0.80
UserMetaMethod · 0.80
KeyMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…