diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-04-07 16:24:51 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-04-11 12:36:54 -0600 |
commit | 698b07b074dc554578ecddd138972702f46d0879 (patch) | |
tree | f171f10bd4f17986cb9120d71263995b28273a7a /node_test.go | |
parent | Update cursor benchmark. (diff) | |
download | dedo-698b07b074dc554578ecddd138972702f46d0879.tar.gz dedo-698b07b074dc554578ecddd138972702f46d0879.tar.xz |
Add nested buckets.
This commit adds the ability to create buckets inside of other buckets.
It also replaces the buckets page with a root bucket.
Fixes #56.
Diffstat (limited to 'node_test.go')
-rw-r--r-- | node_test.go | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/node_test.go b/node_test.go index 8555223..e58a544 100644 --- a/node_test.go +++ b/node_test.go @@ -8,12 +8,12 @@ import ( ) // Ensure that a node can insert a key/value. -func TestNodePut(t *testing.T) { +func TestNode_put(t *testing.T) { n := &node{inodes: make(inodes, 0)} - n.put([]byte("baz"), []byte("baz"), []byte("2"), 0) - n.put([]byte("foo"), []byte("foo"), []byte("0"), 0) - n.put([]byte("bar"), []byte("bar"), []byte("1"), 0) - n.put([]byte("foo"), []byte("foo"), []byte("3"), 0) + n.put([]byte("baz"), []byte("baz"), []byte("2"), 0, 0) + n.put([]byte("foo"), []byte("foo"), []byte("0"), 0, 0) + n.put([]byte("bar"), []byte("bar"), []byte("1"), 0, 0) + n.put([]byte("foo"), []byte("foo"), []byte("3"), 0, leafPageFlag) assert.Equal(t, len(n.inodes), 3) assert.Equal(t, n.inodes[0].key, []byte("bar")) assert.Equal(t, n.inodes[0].value, []byte("1")) @@ -21,10 +21,11 @@ func TestNodePut(t *testing.T) { assert.Equal(t, n.inodes[1].value, []byte("2")) assert.Equal(t, n.inodes[2].key, []byte("foo")) assert.Equal(t, n.inodes[2].value, []byte("3")) + assert.Equal(t, n.inodes[2].flags, uint32(leafPageFlag)) } // Ensure that a node can deserialize from a leaf page. -func TestNodeReadLeafPage(t *testing.T) { +func TestNode_read_LeafPage(t *testing.T) { // Create a page. var buf [4096]byte page := (*page)(unsafe.Pointer(&buf[0])) @@ -55,12 +56,12 @@ func TestNodeReadLeafPage(t *testing.T) { } // Ensure that a node can serialize into a leaf page. -func TestNodeWriteLeafPage(t *testing.T) { +func TestNode_write_LeafPage(t *testing.T) { // Create a node. n := &node{isLeaf: true, inodes: make(inodes, 0)} - n.put([]byte("susy"), []byte("susy"), []byte("que"), 0) - n.put([]byte("ricki"), []byte("ricki"), []byte("lake"), 0) - n.put([]byte("john"), []byte("john"), []byte("johnson"), 0) + n.put([]byte("susy"), []byte("susy"), []byte("que"), 0, 0) + n.put([]byte("ricki"), []byte("ricki"), []byte("lake"), 0, 0) + n.put([]byte("john"), []byte("john"), []byte("johnson"), 0, 0) // Write it to a page. var buf [4096]byte @@ -82,14 +83,14 @@ func TestNodeWriteLeafPage(t *testing.T) { } // Ensure that a node can split into appropriate subgroups. -func TestNodeSplit(t *testing.T) { +func TestNode_split(t *testing.T) { // Create a node. n := &node{inodes: make(inodes, 0)} - n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0) - n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0) - n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0) - n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0) - n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0) + n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0, 0) // Split between 2 & 3. nodes := n.split(100) @@ -100,11 +101,11 @@ func TestNodeSplit(t *testing.T) { } // Ensure that a page with the minimum number of inodes just returns a single node. -func TestNodeSplitWithMinKeys(t *testing.T) { +func TestNode_split_MinKeys(t *testing.T) { // Create a node. n := &node{inodes: make(inodes, 0)} - n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0) - n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0) + n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0) // Split. nodes := n.split(20) @@ -113,14 +114,14 @@ func TestNodeSplitWithMinKeys(t *testing.T) { } // Ensure that a node that has keys that all fit on a page just returns one leaf. -func TestNodeSplitFitsInPage(t *testing.T) { +func TestNode_split_SinglePage(t *testing.T) { // Create a node. n := &node{inodes: make(inodes, 0)} - n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0) - n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0) - n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0) - n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0) - n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0) + n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0, 0) + n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0, 0) // Split. nodes := n.split(4096) |