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

Function TestDropPrefixReadOnly

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

Source from the content-addressed store, hash-verified

497}
498
499func TestDropPrefixReadOnly(t *testing.T) {
500 dir, err := ioutil.TempDir("", "badger-test")
501 require.NoError(t, err)
502 defer removeDir(dir)
503 opts := getTestOptions(dir)
504 opts.ValueLogFileSize = 5 << 20
505 db, err := Open(opts)
506 require.NoError(t, err)
507 N := uint64(1000)
508 populate := func(db *DB) {
509 writer := db.NewWriteBatch()
510 for i := uint64(0); i < N; i++ {
511 require.NoError(t, writer.Set([]byte(key("key", int(i))), val(true)))
512 }
513 require.NoError(t, writer.Flush())
514 }
515
516 populate(db)
517 require.Equal(t, int(N), numKeys(db))
518 require.NoError(t, db.Close())
519
520 opts.ReadOnly = true
521 db2, err := Open(opts)
522 // acquireDirectoryLock returns ErrWindowsNotSupported on Windows. It can be ignored safely.
523 if runtime.GOOS == "windows" {
524 require.Equal(t, err, ErrWindowsNotSupported)
525 } else {
526 require.NoError(t, err)
527 require.Panics(t, func() { db2.DropPrefix([]byte("key0")) })
528 require.NoError(t, db2.Close())
529 }
530}
531
532func TestDropPrefixRace(t *testing.T) {
533 dir, err := ioutil.TempDir("", "badger-test")

Callers

nothing calls this directly

Calls 11

SetMethod · 0.95
FlushMethod · 0.95
removeDirFunction · 0.85
getTestOptionsFunction · 0.85
OpenFunction · 0.85
valFunction · 0.85
numKeysFunction · 0.85
NewWriteBatchMethod · 0.80
DropPrefixMethod · 0.80
keyFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…