MCPcopy Index your code
hub / github.com/nutsdb/nutsdb / TestBatchWrite

Function TestBatchWrite

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

Source from the content-addressed store, hash-verified

18)
19
20func TestBatchWrite(t *testing.T) {
21 TestFlushPanic := func(t *testing.T, db *DB) {
22 wb, err := db.NewWriteBatch()
23 require.NoError(t, err)
24 require.NoError(t, wb.Flush())
25 require.Error(t, ErrCommitAfterFinish, wb.Flush())
26 wb, err = db.NewWriteBatch()
27 require.NoError(t, err)
28 require.NoError(t, wb.Cancel())
29 require.Error(t, ErrCommitAfterFinish, wb.Flush())
30 }
31
32 testEmptyWrite := func(t *testing.T, db *DB) {
33 wb, err := db.NewWriteBatch()
34 require.NoError(t, err)
35 require.NoError(t, wb.Flush())
36 wb, err = db.NewWriteBatch()
37 require.NoError(t, err)
38 require.NoError(t, wb.Flush())
39 wb, err = db.NewWriteBatch()
40 require.NoError(t, err)
41 require.NoError(t, wb.Flush())
42 }
43
44 testWrite := func(t *testing.T, db *DB) {
45 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
46 key := func(i int) []byte {
47 return []byte(fmt.Sprintf("%10d", i))
48 }
49 val := func(i int) []byte {
50 return []byte(fmt.Sprintf("%128d", i))
51 }
52 wb, err := db.NewWriteBatch()
53 require.NoError(t, err)
54 time2.Start()
55 for i := 0; i < N; i++ {
56 require.NoError(t, wb.Put(bucket, key(i), val(i), 0))
57 }
58 require.NoError(t, wb.Flush())
59 // fmt.Printf("Time taken via batch write %v keys: %v\n", N, time2.End())
60
61 time2.Start()
62 if err := db.View(
63 func(tx *Tx) error {
64 for i := 0; i < N; i++ {
65 key := key(i)
66 value, err := tx.Get(bucket, key)
67 if err != nil {
68 return err
69 }
70 require.Equal(t, val(i), value)
71 }
72 return nil
73 }); err != nil {
74 log.Println(err)
75 }
76
77 // fmt.Printf("Time taken via db.View %v keys: %v\n", N, time2.End())

Callers

nothing calls this directly

Calls 15

FlushMethod · 0.95
CancelMethod · 0.95
PutMethod · 0.95
DeleteMethod · 0.95
txCreateBucketFunction · 0.85
OpenFunction · 0.85
WithDirFunction · 0.85
WithEntryIdxModeFunction · 0.85
WithMaxBatchCountFunction · 0.85
WithMaxBatchSizeFunction · 0.85
NewWriteBatchMethod · 0.80
ViewMethod · 0.80

Tested by

no test coverage detected