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

Function TestNode_split

node_test.go:110–134  ·  view source on GitHub ↗

Ensure that a node can split into appropriate subgroups.

(t *testing.T)

Source from the content-addressed store, hash-verified

108
109// Ensure that a node can split into appropriate subgroups.
110func TestNode_split(t *testing.T) {
111 // Create a node.
112 m := &common.Meta{}
113 m.SetPgid(1)
114 n := &node{inodes: make(common.Inodes, 0), bucket: &Bucket{tx: &Tx{db: &DB{}, meta: m}}}
115 n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0)
116 n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0)
117 n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0, 0)
118 n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0, 0)
119 n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0, 0)
120
121 // Split between 2 & 3.
122 n.split(100)
123
124 var parent = n.parent
125 if len(parent.children) != 2 {
126 t.Fatalf("exp=2; got=%d", len(parent.children))
127 }
128 if len(parent.children[0].inodes) != 2 {
129 t.Fatalf("exp=2; got=%d", len(parent.children[0].inodes))
130 }
131 if len(parent.children[1].inodes) != 3 {
132 t.Fatalf("exp=3; got=%d", len(parent.children[1].inodes))
133 }
134}
135
136// Ensure that a page with the minimum number of inodes just returns a single node.
137func TestNode_split_MinKeys(t *testing.T) {

Callers

nothing calls this directly

Calls 4

SetPgidMethod · 0.95
putMethod · 0.95
splitMethod · 0.95
FatalfMethod · 0.65

Tested by

no test coverage detected