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

Function TestBucket_Stats_Nested

bucket_test.go:1529–1627  ·  view source on GitHub ↗

Ensure a bucket can calculate stats.

(t *testing.T)

Source from the content-addressed store, hash-verified

1527
1528// Ensure a bucket can calculate stats.
1529func TestBucket_Stats_Nested(t *testing.T) {
1530 db := btesting.MustCreateDB(t)
1531
1532 if err := db.Update(func(tx *bolt.Tx) error {
1533 b, err := tx.CreateBucket([]byte("foo"))
1534 if err != nil {
1535 t.Fatal(err)
1536 }
1537 for i := 0; i < 100; i++ {
1538 if err := b.Put([]byte(fmt.Sprintf("%02d", i)), []byte(fmt.Sprintf("%02d", i))); err != nil {
1539 t.Fatal(err)
1540 }
1541 }
1542
1543 bar, err := b.CreateBucket([]byte("bar"))
1544 if err != nil {
1545 t.Fatal(err)
1546 }
1547 for i := 0; i < 10; i++ {
1548 if err := bar.Put([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i))); err != nil {
1549 t.Fatal(err)
1550 }
1551 }
1552
1553 baz, err := bar.CreateBucket([]byte("baz"))
1554 if err != nil {
1555 t.Fatal(err)
1556 }
1557 for i := 0; i < 10; i++ {
1558 if err := baz.Put([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i))); err != nil {
1559 t.Fatal(err)
1560 }
1561 }
1562
1563 return nil
1564 }); err != nil {
1565 t.Fatal(err)
1566 }
1567
1568 db.MustCheck()
1569
1570 if err := db.View(func(tx *bolt.Tx) error {
1571 b := tx.Bucket([]byte("foo"))
1572 stats := b.Stats()
1573 if stats.BranchPageN != 0 {
1574 t.Fatalf("unexpected BranchPageN: %d", stats.BranchPageN)
1575 } else if stats.BranchOverflowN != 0 {
1576 t.Fatalf("unexpected BranchOverflowN: %d", stats.BranchOverflowN)
1577 } else if stats.LeafPageN != 2 {
1578 t.Fatalf("unexpected LeafPageN: %d", stats.LeafPageN)
1579 } else if stats.LeafOverflowN != 0 {
1580 t.Fatalf("unexpected LeafOverflowN: %d", stats.LeafOverflowN)
1581 } else if stats.KeyN != 122 {
1582 t.Fatalf("unexpected KeyN: %d", stats.KeyN)
1583 } else if stats.Depth != 3 {
1584 t.Fatalf("unexpected Depth: %d", stats.Depth)
1585 } else if stats.BranchInuse != 0 {
1586 t.Fatalf("unexpected BranchInuse: %d", stats.BranchInuse)

Callers

nothing calls this directly

Calls 11

MustCreateDBFunction · 0.92
UpdateMethod · 0.80
MustCheckMethod · 0.80
ViewMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
InfoMethod · 0.65
CreateBucketMethod · 0.45
PutMethod · 0.45
BucketMethod · 0.45
StatsMethod · 0.45

Tested by

no test coverage detected