MCPcopy
hub / github.com/etcd-io/bbolt / TestDB_MaxSizeExceededCanOpen

Function TestDB_MaxSizeExceededCanOpen

db_test.go:1601–1627  ·  view source on GitHub ↗

Ensure that opening a database that is beyond the maximum size succeeds The maximum size should only apply to growing the data file https://github.com/etcd-io/bbolt/issues/928

(t *testing.T)

Source from the content-addressed store, hash-verified

1599// The maximum size should only apply to growing the data file
1600// https://github.com/etcd-io/bbolt/issues/928
1601func TestDB_MaxSizeExceededCanOpen(t *testing.T) {
1602 // Open a data file.
1603 db := createFilledDB(t, nil, 4*1024*1024, 2000) // adjust allocation jumps to 4 MiB, fill with 2000, 1KB keys
1604 path := db.Path()
1605
1606 // Insert a reasonable amount of data below the max size.
1607 err := fillDBWithKeys(db, 2000, 1000)
1608 require.NoError(t, err, "fillDbWithKeys should succeed")
1609
1610 err = db.Close()
1611 require.NoError(t, err, "Close should succeed")
1612
1613 // The data file should be 4 MiB now (expanded once from zero).
1614 minimumSizeForTest := int64(1024 * 1024)
1615 newSz := fileSize(path)
1616 require.GreaterOrEqual(t, newSz, minimumSizeForTest, "unexpected new file size: %d. Expected at least %d", newSz, minimumSizeForTest)
1617
1618 // Now try to re-open the database with an extremely small max size
1619 t.Logf("Reopening bbolt DB at: %s", path)
1620 db, err = btesting.OpenDBWithOption(t, path, &bolt.Options{
1621 MaxSize: 1,
1622 })
1623 assert.NoError(t, err, "Should be able to open database bigger than MaxSize")
1624
1625 err = db.Close()
1626 require.NoError(t, err, "Closing the re-opened database should succeed")
1627}
1628
1629// Ensure that opening a database that is beyond the maximum size succeeds,
1630// even when InitialMmapSize is above the limit (mmaps should not affect file size)

Callers

nothing calls this directly

Calls 6

OpenDBWithOptionFunction · 0.92
createFilledDBFunction · 0.85
fillDBWithKeysFunction · 0.85
fileSizeFunction · 0.85
PathMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected