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

Function TestBucket_Stats_Large

bucket_test.go:1735–1821  ·  view source on GitHub ↗

Ensure a large bucket can calculate stats.

(t *testing.T)

Source from the content-addressed store, hash-verified

1733
1734// Ensure a large bucket can calculate stats.
1735func TestBucket_Stats_Large(t *testing.T) {
1736 if testing.Short() {
1737 t.Skip("skipping test in short mode.")
1738 }
1739
1740 db := btesting.MustCreateDB(t)
1741
1742 var index int
1743 for i := 0; i < 100; i++ {
1744 // Add bucket with lots of keys.
1745 if err := db.Update(func(tx *bolt.Tx) error {
1746 b, err := tx.CreateBucketIfNotExists([]byte("widgets"))
1747 if err != nil {
1748 t.Fatal(err)
1749 }
1750 for i := 0; i < 1000; i++ {
1751 if err := b.Put([]byte(strconv.Itoa(index)), []byte(strconv.Itoa(index))); err != nil {
1752 t.Fatal(err)
1753 }
1754 index++
1755 }
1756 return nil
1757 }); err != nil {
1758 t.Fatal(err)
1759 }
1760 }
1761
1762 db.MustCheck()
1763
1764 pageSize2stats := map[int]bolt.BucketStats{
1765 4096: {
1766 BranchPageN: 13,
1767 BranchOverflowN: 0,
1768 LeafPageN: 1196,
1769 LeafOverflowN: 0,
1770 KeyN: 100000,
1771 Depth: 3,
1772 BranchAlloc: 53248,
1773 BranchInuse: 25257,
1774 LeafAlloc: 4898816,
1775 LeafInuse: 2596916,
1776 BucketN: 1,
1777 InlineBucketN: 0,
1778 InlineBucketInuse: 0},
1779 16384: {
1780 BranchPageN: 1,
1781 BranchOverflowN: 0,
1782 LeafPageN: 292,
1783 LeafOverflowN: 0,
1784 KeyN: 100000,
1785 Depth: 2,
1786 BranchAlloc: 16384,
1787 BranchInuse: 6094,
1788 LeafAlloc: 4784128,
1789 LeafInuse: 2582452,
1790 BucketN: 1,
1791 InlineBucketN: 0,
1792 InlineBucketInuse: 0},

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected