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

Function TestSetIfAbsentAsync

db_test.go:1072–1113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1070}
1071
1072func TestSetIfAbsentAsync(t *testing.T) {
1073 dir, err := ioutil.TempDir("", "badger-test")
1074 require.NoError(t, err)
1075 defer removeDir(dir)
1076 kv, _ := Open(getTestOptions(dir))
1077
1078 bkey := func(i int) []byte {
1079 return []byte(fmt.Sprintf("%09d", i))
1080 }
1081
1082 f := func(err error) {}
1083
1084 n := 1000
1085 for i := 0; i < n; i++ {
1086 // if (i % 10) == 0 {
1087 // t.Logf("Put i=%d\n", i)
1088 // }
1089 txn := kv.NewTransaction(true)
1090 _, err = txn.Get(bkey(i))
1091 require.Equal(t, ErrKeyNotFound, err)
1092 require.NoError(t, txn.SetEntry(NewEntry(bkey(i), nil).WithMeta(byte(i%127))))
1093 txn.CommitWith(f)
1094 }
1095
1096 require.NoError(t, kv.Close())
1097 kv, err = Open(getTestOptions(dir))
1098 require.NoError(t, err)
1099
1100 opt := DefaultIteratorOptions
1101 txn := kv.NewTransaction(false)
1102 var count int
1103 it := txn.NewIterator(opt)
1104 {
1105 t.Log("Starting first basic iteration")
1106 for it.Rewind(); it.Valid(); it.Next() {
1107 count++
1108 }
1109 require.EqualValues(t, n, count)
1110 }
1111 require.Equal(t, n, count)
1112 require.NoError(t, kv.Close())
1113}
1114
1115func TestGetSetRace(t *testing.T) {
1116 runBadgerTest(t, nil, func(t *testing.T, db *DB) {

Callers

nothing calls this directly

Calls 14

RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
removeDirFunction · 0.85
OpenFunction · 0.85
getTestOptionsFunction · 0.85
NewEntryFunction · 0.85
NewTransactionMethod · 0.80
WithMetaMethod · 0.80
CommitWithMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…