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

Function TestOpen_Size_Large

db_test.go:331–394  ·  view source on GitHub ↗

Ensure that opening a database beyond the max step size does not increase its size. https://github.com/boltdb/bolt/issues/303

(t *testing.T)

Source from the content-addressed store, hash-verified

329// Ensure that opening a database beyond the max step size does not increase its size.
330// https://github.com/boltdb/bolt/issues/303
331func TestOpen_Size_Large(t *testing.T) {
332 if testing.Short() {
333 t.Skip("short mode")
334 }
335
336 // Open a data file.
337 db := btesting.MustCreateDB(t)
338 path := db.Path()
339
340 pagesize := db.Info().PageSize
341
342 // Insert until we get above the minimum 4MB size.
343 var index uint64
344 for i := 0; i < 10000; i++ {
345 if err := db.Update(func(tx *bolt.Tx) error {
346 b, _ := tx.CreateBucketIfNotExists([]byte("data"))
347 for j := 0; j < 1000; j++ {
348 if err := b.Put(u64tob(index), make([]byte, 50)); err != nil {
349 t.Fatal(err)
350 }
351 index++
352 }
353 return nil
354 }); err != nil {
355 t.Fatal(err)
356 }
357 }
358
359 // Close database and grab the size.
360 if err := db.Close(); err != nil {
361 t.Fatal(err)
362 }
363 sz := fileSize(path)
364 if sz == 0 {
365 t.Fatalf("unexpected new file size: %d", sz)
366 } else if sz < (1 << 30) {
367 t.Fatalf("expected larger initial size: %d", sz)
368 }
369
370 // Reopen database, update, and check size again.
371 db0, err := bolt.Open(path, 0600, nil)
372 if err != nil {
373 t.Fatal(err)
374 }
375 if err := db0.Update(func(tx *bolt.Tx) error {
376 return tx.Bucket([]byte("data")).Put([]byte{0}, []byte{0})
377 }); err != nil {
378 t.Fatal(err)
379 }
380 if err := db0.Close(); err != nil {
381 t.Fatal(err)
382 }
383
384 newSz := fileSize(path)
385 if newSz == 0 {
386 t.Fatalf("unexpected new file size: %d", newSz)
387 }
388

Callers

nothing calls this directly

Calls 12

MustCreateDBFunction · 0.92
u64tobFunction · 0.85
fileSizeFunction · 0.85
UpdateMethod · 0.80
InfoMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65
PathMethod · 0.45
PutMethod · 0.45
CloseMethod · 0.45
BucketMethod · 0.45

Tested by

no test coverage detected