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

Function TestNode_write_LeafPage

node_test.go:76–107  ·  view source on GitHub ↗

Ensure that a node can serialize into a leaf page.

(t *testing.T)

Source from the content-addressed store, hash-verified

74
75// Ensure that a node can serialize into a leaf page.
76func TestNode_write_LeafPage(t *testing.T) {
77 // Create a node.
78 m := &common.Meta{}
79 m.SetPgid(1)
80 n := &node{isLeaf: true, inodes: make(common.Inodes, 0), bucket: &Bucket{tx: &Tx{db: &DB{}, meta: m}}}
81 n.put([]byte("susy"), []byte("susy"), []byte("que"), 0, 0)
82 n.put([]byte("ricki"), []byte("ricki"), []byte("lake"), 0, 0)
83 n.put([]byte("john"), []byte("john"), []byte("johnson"), 0, 0)
84
85 // Write it to a page.
86 var buf [4096]byte
87 p := (*common.Page)(unsafe.Pointer(&buf[0]))
88 n.write(p)
89
90 // Read the page back in.
91 n2 := &node{}
92 n2.read(p)
93
94 // Check that the two pages are the same.
95 if len(n2.inodes) != 3 {
96 t.Fatalf("exp=3; got=%d", len(n2.inodes))
97 }
98 if k, v := n2.inodes[0].Key(), n2.inodes[0].Value(); string(k) != "john" || string(v) != "johnson" {
99 t.Fatalf("exp=<john,johnson>; got=<%s,%s>", k, v)
100 }
101 if k, v := n2.inodes[1].Key(), n2.inodes[1].Value(); string(k) != "ricki" || string(v) != "lake" {
102 t.Fatalf("exp=<ricki,lake>; got=<%s,%s>", k, v)
103 }
104 if k, v := n2.inodes[2].Key(), n2.inodes[2].Value(); string(k) != "susy" || string(v) != "que" {
105 t.Fatalf("exp=<susy,que>; got=<%s,%s>", k, v)
106 }
107}
108
109// Ensure that a node can split into appropriate subgroups.
110func TestNode_split(t *testing.T) {

Callers

nothing calls this directly

Calls 7

SetPgidMethod · 0.95
putMethod · 0.95
writeMethod · 0.95
readMethod · 0.95
FatalfMethod · 0.65
KeyMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected