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

Function TestDropAllManaged

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

Source from the content-addressed store, hash-verified

56}
57
58func TestDropAllManaged(t *testing.T) {
59 dir, err := ioutil.TempDir("", "badger-test")
60 require.NoError(t, err)
61 defer removeDir(dir)
62 opts := getTestOptions(dir)
63 opts.managedTxns = true
64 opts.ValueLogFileSize = 5 << 20
65 db, err := Open(opts)
66 require.NoError(t, err)
67
68 N := uint64(10000)
69 populate := func(db *DB, start uint64) {
70 var wg sync.WaitGroup
71 for i := start; i < start+N; i++ {
72 wg.Add(1)
73 txn := db.NewTransactionAt(math.MaxUint64, true)
74 require.NoError(t, txn.SetEntry(NewEntry([]byte(key("key", int(i))), val(true))))
75 require.NoError(t, txn.CommitAt(uint64(i), func(err error) {
76 require.NoError(t, err)
77 wg.Done()
78 }))
79 }
80 wg.Wait()
81 }
82
83 populate(db, N)
84 require.Equal(t, int(N), numKeysManaged(db, math.MaxUint64))
85
86 require.NoError(t, db.DropAll())
87 require.NoError(t, db.DropAll()) // Just call it twice, for fun.
88 require.Equal(t, 0, numKeysManaged(db, math.MaxUint64))
89
90 // Check that we can still write to db, and using lower timestamps.
91 populate(db, 1)
92 require.Equal(t, int(N), numKeysManaged(db, math.MaxUint64))
93 require.NoError(t, db.Close())
94
95 // Ensure that value log is correctly replayed, that we are preserving badgerHead.
96 opts.managedTxns = true
97 db2, err := Open(opts)
98 require.NoError(t, err)
99 require.Equal(t, int(N), numKeysManaged(db2, math.MaxUint64))
100 require.NoError(t, db2.Close())
101}
102
103func TestDropAll(t *testing.T) {
104 dir, err := ioutil.TempDir("", "badger-test")

Callers

nothing calls this directly

Calls 15

removeDirFunction · 0.85
getTestOptionsFunction · 0.85
OpenFunction · 0.85
NewEntryFunction · 0.85
valFunction · 0.85
numKeysManagedFunction · 0.85
NewTransactionAtMethod · 0.80
CommitAtMethod · 0.80
DropAllMethod · 0.80
keyFunction · 0.70
CloseMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…