Ensure that a node can split into appropriate subgroups.
(t *testing.T)
| 108 | |
| 109 | // Ensure that a node can split into appropriate subgroups. |
| 110 | func 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. |
| 137 | func TestNode_split_MinKeys(t *testing.T) { |