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

Function TestWriteBatchManaged

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

Source from the content-addressed store, hash-verified

642 })
643}
644func TestWriteBatchManaged(t *testing.T) {
645 key := func(i int) []byte {
646 return []byte(fmt.Sprintf("%10d", i))
647 }
648 val := func(i int) []byte {
649 return []byte(fmt.Sprintf("%128d", i))
650 }
651 opt := DefaultOptions("")
652 opt.managedTxns = true
653 opt.MaxTableSize = 1 << 15 // This would create multiple transactions in write batch.
654 runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
655 wb := db.NewManagedWriteBatch()
656 defer wb.Cancel()
657
658 N, M := 50000, 1000
659 start := time.Now()
660
661 for i := 0; i < N; i++ {
662 require.NoError(t, wb.SetEntryAt(&Entry{Key: key(i), Value: val(i)}, 1))
663 }
664 for i := 0; i < M; i++ {
665 require.NoError(t, wb.DeleteAt(key(i), 2))
666 }
667 require.NoError(t, wb.Flush())
668 t.Logf("Time taken for %d writes (w/ test options): %s\n", N+M, time.Since(start))
669
670 err := db.View(func(txn *Txn) error {
671 itr := txn.NewIterator(DefaultIteratorOptions)
672 defer itr.Close()
673
674 i := M
675 for itr.Rewind(); itr.Valid(); itr.Next() {
676 item := itr.Item()
677 require.Equal(t, string(key(i)), string(item.Key()))
678 require.Equal(t, item.Version(), uint64(1))
679 valcopy, err := item.ValueCopy(nil)
680 require.NoError(t, err)
681 require.Equal(t, val(i), valcopy)
682 i++
683 }
684 require.Equal(t, N, i)
685 return nil
686 })
687 require.NoError(t, err)
688 })
689}
690
691func TestWriteBatchDuplicate(t *testing.T) {
692 N := 10

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
NewManagedWriteBatchMethod · 0.80
CancelMethod · 0.80
SetEntryAtMethod · 0.80
DeleteAtMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…