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

Function TestDropAllWithPendingTxn

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

Source from the content-addressed store, hash-verified

180}
181
182func TestDropAllWithPendingTxn(t *testing.T) {
183 dir, err := ioutil.TempDir("", "badger-test")
184 require.NoError(t, err)
185 defer removeDir(dir)
186 opts := getTestOptions(dir)
187 opts.ValueLogFileSize = 5 << 20
188 db, err := Open(opts)
189 require.NoError(t, err)
190 defer func() {
191 require.NoError(t, db.Close())
192 }()
193
194 N := uint64(10000)
195 populate := func(db *DB) {
196 writer := db.NewWriteBatch()
197 for i := uint64(0); i < N; i++ {
198 require.NoError(t, writer.Set([]byte(key("key", int(i))), val(true)))
199 }
200 require.NoError(t, writer.Flush())
201 }
202
203 populate(db)
204 require.Equal(t, int(N), numKeys(db))
205
206 txn := db.NewTransaction(true)
207
208 var wg sync.WaitGroup
209 wg.Add(1)
210 go func() {
211 defer wg.Done()
212 itr := txn.NewIterator(DefaultIteratorOptions)
213 defer itr.Close()
214
215 var keys []string
216 for {
217 var count int
218 for itr.Rewind(); itr.Valid(); itr.Next() {
219 count++
220 item := itr.Item()
221 keys = append(keys, string(item.KeyCopy(nil)))
222 _, err := item.ValueCopy(nil)
223 if err != nil {
224 t.Logf("Got error during value copy: %v", err)
225 return
226 }
227 }
228 t.Logf("Got number of keys: %d\n", count)
229 for _, key := range keys {
230 item, err := txn.Get([]byte(key))
231 if err != nil {
232 t.Logf("Got error during key lookup: %v", err)
233 return
234 }
235 if _, err := item.ValueCopy(nil); err != nil {
236 t.Logf("Got error during second value copy: %v", err)
237 return
238 }
239 }

Callers

nothing calls this directly

Calls 15

SetMethod · 0.95
FlushMethod · 0.95
CloseMethod · 0.95
RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
removeDirFunction · 0.85
getTestOptionsFunction · 0.85
OpenFunction · 0.85
valFunction · 0.85
numKeysFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…