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

Function TestDB_HugeValue

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

Source from the content-addressed store, hash-verified

1860}
1861
1862func TestDB_HugeValue(t *testing.T) {
1863 dbPath := filepath.Join(t.TempDir(), "db")
1864 db, err := bolt.Open(dbPath, 0600, nil)
1865 require.NoError(t, err)
1866 defer func() {
1867 require.NoError(t, db.Close())
1868 }()
1869
1870 maxSize := 0xFFFFFFF + 1
1871 // On 32 bit systems, the MaxAllocSize is 0xFFFFFFF (268435455,
1872 // roughly 256MB), and the test will fail for sure, so we reduce
1873 // the maxSize by half in such case.
1874 if maxSize > common.MaxAllocSize {
1875 maxSize = maxSize / 2
1876 }
1877 data := make([]byte, maxSize)
1878
1879 _ = db.Update(func(tx *bolt.Tx) error {
1880 b, err := tx.CreateBucketIfNotExists([]byte("data"))
1881 require.NoError(t, err)
1882
1883 err = b.Put([]byte("key"), data)
1884 require.NoError(t, err)
1885
1886 return nil
1887 })
1888}
1889
1890func ExampleDB_Update() {
1891 // Open the database.

Callers

nothing calls this directly

Calls 4

UpdateMethod · 0.80
CloseMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected