MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestDB_CommitBuffer

Function TestDB_CommitBuffer

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

Source from the content-addressed store, hash-verified

1388}
1389
1390func TestDB_CommitBuffer(t *testing.T) {
1391 bucket := "bucket"
1392
1393 opts := DefaultOptions
1394 opts.CommitBufferSize = 8 * MB
1395 runNutsDBTest(t, &opts, func(t *testing.T, db *DB) {
1396 require.Equal(t, int64(8*MB), db.opt.CommitBufferSize)
1397 // When the database starts, the commit buffer should be allocated with the size of CommitBufferSize.
1398 require.Equal(t, 0, db.commitBuffer.Len())
1399 require.Equal(t, db.opt.CommitBufferSize, int64(db.commitBuffer.Cap()))
1400 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
1401 txPut(t, db, bucket, testutils.GetTestBytes(0), testutils.GetRandomBytes(24), Persistent, nil, nil)
1402
1403 // When tx is committed, content of commit buffer should be empty, but do not release memory
1404 require.Equal(t, 0, db.commitBuffer.Len())
1405 require.Equal(t, db.opt.CommitBufferSize, int64(db.commitBuffer.Cap()))
1406 })
1407
1408 opts = DefaultOptions
1409 opts.CommitBufferSize = 1 * KB
1410 runNutsDBTest(t, &opts, func(t *testing.T, db *DB) {
1411 require.Equal(t, int64(1*KB), db.opt.CommitBufferSize)
1412
1413 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
1414 err := db.Update(func(tx *Tx) error {
1415 // making this tx big enough, it should not use the commit buffer
1416 for i := 0; i < 1000; i++ {
1417 err := tx.Put(bucket, testutils.GetTestBytes(i), testutils.GetRandomBytes(1024), Persistent)
1418 require.NoError(t, err)
1419 }
1420 return nil
1421 })
1422 require.NoError(t, err)
1423
1424 require.Equal(t, 0, db.commitBuffer.Len())
1425 require.Equal(t, db.opt.CommitBufferSize, int64(db.commitBuffer.Cap()))
1426 })
1427}
1428
1429func TestDB_DeleteBucket(t *testing.T) {
1430 runNutsDBTest(t, nil, func(t *testing.T, db *DB) {

Callers

nothing calls this directly

Calls 8

GetTestBytesFunction · 0.92
GetRandomBytesFunction · 0.92
runNutsDBTestFunction · 0.85
txCreateBucketFunction · 0.85
txPutFunction · 0.85
UpdateMethod · 0.80
LenMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected