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

Function TestUpdateAndView

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

Source from the content-addressed store, hash-verified

145}
146
147func TestUpdateAndView(t *testing.T) {
148 runBadgerTest(t, nil, func(t *testing.T, db *DB) {
149 err := db.Update(func(txn *Txn) error {
150 for i := 0; i < 10; i++ {
151 entry := NewEntry([]byte(fmt.Sprintf("key%d", i)), []byte(fmt.Sprintf("val%d", i)))
152 if err := txn.SetEntry(entry); err != nil {
153 return err
154 }
155 }
156 return nil
157 })
158 require.NoError(t, err)
159
160 err = db.View(func(txn *Txn) error {
161 for i := 0; i < 10; i++ {
162 item, err := txn.Get([]byte(fmt.Sprintf("key%d", i)))
163 if err != nil {
164 return err
165 }
166
167 expected := []byte(fmt.Sprintf("val%d", i))
168 if err := item.Value(func(val []byte) error {
169 require.Equal(t, expected, val,
170 "Invalid value for key %q. expected: %q, actual: %q",
171 item.Key(), expected, val)
172 return nil
173 }); err != nil {
174 return err
175 }
176 }
177 return nil
178 })
179 require.NoError(t, err)
180 })
181}
182
183func TestConcurrentWrite(t *testing.T) {
184 runBadgerTest(t, nil, func(t *testing.T, db *DB) {

Callers

nothing calls this directly

Calls 8

runBadgerTestFunction · 0.85
NewEntryFunction · 0.85
ViewMethod · 0.80
ValueMethod · 0.65
KeyMethod · 0.65
UpdateMethod · 0.45
SetEntryMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…