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

Function TestWriteBatchManagedMode

managed_db_test.go:598–643  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

596}
597
598func TestWriteBatchManagedMode(t *testing.T) {
599 key := func(i int) []byte {
600 return []byte(fmt.Sprintf("%10d", i))
601 }
602 val := func(i int) []byte {
603 return []byte(fmt.Sprintf("%128d", i))
604 }
605 opt := DefaultOptions("")
606 opt.managedTxns = true
607 opt.MaxTableSize = 1 << 20 // This would create multiple transactions in write batch.
608 runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
609 wb := db.NewWriteBatchAt(1)
610 defer wb.Cancel()
611
612 N, M := 50000, 1000
613 start := time.Now()
614
615 for i := 0; i < N; i++ {
616 require.NoError(t, wb.Set(key(i), val(i)))
617 }
618 for i := 0; i < M; i++ {
619 require.NoError(t, wb.Delete(key(i)))
620 }
621 require.NoError(t, wb.Flush())
622 t.Logf("Time taken for %d writes (w/ test options): %s\n", N+M, time.Since(start))
623
624 err := db.View(func(txn *Txn) error {
625 itr := txn.NewIterator(DefaultIteratorOptions)
626 defer itr.Close()
627
628 i := M
629 for itr.Rewind(); itr.Valid(); itr.Next() {
630 item := itr.Item()
631 require.Equal(t, string(key(i)), string(item.Key()))
632 require.Equal(t, item.Version(), uint64(1))
633 valcopy, err := item.ValueCopy(nil)
634 require.NoError(t, err)
635 require.Equal(t, val(i), valcopy)
636 i++
637 }
638 require.Equal(t, N, i)
639 return nil
640 })
641 require.NoError(t, err)
642 })
643}
644func TestWriteBatchManaged(t *testing.T) {
645 key := func(i int) []byte {
646 return []byte(fmt.Sprintf("%10d", i))

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
DefaultOptionsFunction · 0.85
runBadgerTestFunction · 0.85
valFunction · 0.85
NewWriteBatchAtMethod · 0.80
CancelMethod · 0.80
ViewMethod · 0.80
VersionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…