Commit fbc00f11 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f0888bd2
...@@ -54,7 +54,7 @@ type bmapping interface { ...@@ -54,7 +54,7 @@ type bmapping interface {
Get(context.Context, KEY) (interface{}, bool, error) Get(context.Context, KEY) (interface{}, bool, error)
} }
func TestBucket(t *testing.T) { func TestBTree(t *testing.T) {
ctx := context.Background() ctx := context.Background()
stor, err := zodb.OpenStorage(ctx, "testdata/1.fs", &zodb.OpenOptions{ReadOnly: true}) stor, err := zodb.OpenStorage(ctx, "testdata/1.fs", &zodb.OpenOptions{ReadOnly: true})
if err != nil { if err != nil {
...@@ -70,7 +70,7 @@ func TestBucket(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestBucket(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
for _, tt := range _bucketTestv { for _, tt := range smallTestv {
xobj, err := conn.Get(ctx, tt.oid) xobj, err := conn.Get(ctx, tt.oid)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -119,4 +119,30 @@ func TestBucket(t *testing.T) { ...@@ -119,4 +119,30 @@ func TestBucket(t *testing.T) {
// XXX check keys, values directly (i.e. there is nothing else) // XXX check keys, values directly (i.e. there is nothing else)
} }
} }
// B3 is a large BTree with {i: i} data.
xB3, err := conn.Get(ctx, B3_oid)
if err != nil {
t.Fatal(err)
}
B3, ok := xB3.(*BTree)
if !ok {
t.Fatalf("B3: %v; got %T; want BTree", B3_oid, xB3)
}
for i := KEY(0); i <= B3_maxkey; i++ {
v, ok, err := B3.Get(ctx, i)
if err != nil {
t.Fatal(err)
}
if !ok {
t.Fatalf("B3: get %v -> ø; want %v", i, i)
}
if int64(i) != v {
t.Fatalf("B3: get %v -> %v; want %v", i, v, i)
}
}
// XXX check links
} }
...@@ -70,17 +70,13 @@ def main(): ...@@ -70,17 +70,13 @@ def main():
s += "}}," s += "}},"
emit("\t"+s) emit("\t"+s)
emit("\nvar _bucketTestv = [...]testEntry{") emit("\nvar smallTestv = [...]testEntry{")
for b in (b0, b1, b2, B0, B1, B2): for b in (b0, b1, b2, B0, B1, B2):
emititems(b) emititems(b)
emit("}") emit("}")
# emit("\nvar _btreeTestv = [...]testEntry{") emit("\nconst B3_oid = %s" % u64(B3._p_oid))
# for B in (B0, B1, B2): # XXX + B3 emit("const B3_maxkey = %d" % B3.maxKey())
# emititems(B)
# emit("}")
# XXX B3
conn.close() conn.close()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
package btree package btree
var _bucketTestv = [...]testEntry{ var smallTestv = [...]testEntry{
testEntry{oid: 6, kind: kindBucket, itemv: []kv{}}, testEntry{oid: 6, kind: kindBucket, itemv: []kv{}},
testEntry{oid: 3, kind: kindBucket, itemv: []kv{{10, int64(17)}, }}, testEntry{oid: 3, kind: kindBucket, itemv: []kv{{10, int64(17)}, }},
testEntry{oid: 1, kind: kindBucket, itemv: []kv{{15, int64(1)}, {23, "hello"}, }}, testEntry{oid: 1, kind: kindBucket, itemv: []kv{{15, int64(1)}, {23, "hello"}, }},
...@@ -10,3 +10,6 @@ var _bucketTestv = [...]testEntry{ ...@@ -10,3 +10,6 @@ var _bucketTestv = [...]testEntry{
testEntry{oid: 7, kind: kindBTree, itemv: []kv{{5, int64(4)}, }}, testEntry{oid: 7, kind: kindBTree, itemv: []kv{{5, int64(4)}, }},
testEntry{oid: 4, kind: kindBTree, itemv: []kv{{7, int64(3)}, {9, "world"}, }}, testEntry{oid: 4, kind: kindBTree, itemv: []kv{{7, int64(3)}, {9, "world"}, }},
} }
const B3_oid = 5
const B3_maxkey = 9999
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment