Ensure a bucket can calculate stats.
(t *testing.T)
| 1405 | |
| 1406 | // Ensure a bucket can calculate stats. |
| 1407 | func TestBucket_Stats_Small(t *testing.T) { |
| 1408 | db := btesting.MustCreateDB(t) |
| 1409 | |
| 1410 | if err := db.Update(func(tx *bolt.Tx) error { |
| 1411 | // Add a bucket that fits on a single root leaf. |
| 1412 | b, err := tx.CreateBucket([]byte("whozawhats")) |
| 1413 | if err != nil { |
| 1414 | t.Fatal(err) |
| 1415 | } |
| 1416 | if err := b.Put([]byte("foo"), []byte("bar")); err != nil { |
| 1417 | t.Fatal(err) |
| 1418 | } |
| 1419 | |
| 1420 | return nil |
| 1421 | }); err != nil { |
| 1422 | t.Fatal(err) |
| 1423 | } |
| 1424 | |
| 1425 | db.MustCheck() |
| 1426 | |
| 1427 | if err := db.View(func(tx *bolt.Tx) error { |
| 1428 | b := tx.Bucket([]byte("whozawhats")) |
| 1429 | stats := b.Stats() |
| 1430 | if stats.BranchPageN != 0 { |
| 1431 | t.Fatalf("unexpected BranchPageN: %d", stats.BranchPageN) |
| 1432 | } else if stats.BranchOverflowN != 0 { |
| 1433 | t.Fatalf("unexpected BranchOverflowN: %d", stats.BranchOverflowN) |
| 1434 | } else if stats.LeafPageN != 0 { |
| 1435 | t.Fatalf("unexpected LeafPageN: %d", stats.LeafPageN) |
| 1436 | } else if stats.LeafOverflowN != 0 { |
| 1437 | t.Fatalf("unexpected LeafOverflowN: %d", stats.LeafOverflowN) |
| 1438 | } else if stats.KeyN != 1 { |
| 1439 | t.Fatalf("unexpected KeyN: %d", stats.KeyN) |
| 1440 | } else if stats.Depth != 1 { |
| 1441 | t.Fatalf("unexpected Depth: %d", stats.Depth) |
| 1442 | } else if stats.BranchInuse != 0 { |
| 1443 | t.Fatalf("unexpected BranchInuse: %d", stats.BranchInuse) |
| 1444 | } else if stats.LeafInuse != 0 { |
| 1445 | t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse) |
| 1446 | } |
| 1447 | |
| 1448 | if db.Info().PageSize == 4096 { |
| 1449 | if stats.BranchAlloc != 0 { |
| 1450 | t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc) |
| 1451 | } else if stats.LeafAlloc != 0 { |
| 1452 | t.Fatalf("unexpected LeafAlloc: %d", stats.LeafAlloc) |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | if stats.BucketN != 1 { |
| 1457 | t.Fatalf("unexpected BucketN: %d", stats.BucketN) |
| 1458 | } else if stats.InlineBucketN != 1 { |
| 1459 | t.Fatalf("unexpected InlineBucketN: %d", stats.InlineBucketN) |
| 1460 | } else if stats.InlineBucketInuse != 16+16+6 { |
| 1461 | t.Fatalf("unexpected InlineBucketInuse: %d", stats.InlineBucketInuse) |
| 1462 | } |
| 1463 | |
| 1464 | return nil |