Commit d4ff5502 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 10480280
...@@ -36,12 +36,24 @@ type kv struct { ...@@ -36,12 +36,24 @@ type kv struct {
value interface{} value interface{}
} }
type bkind int
const (
kindBucket bkind = iota
kindBTree
)
// testEntry is information about a Bucket or a BTree. // testEntry is information about a Bucket or a BTree.
type testEntry struct { type testEntry struct {
oid zodb.Oid oid zodb.Oid
kind bkind
itemv []kv itemv []kv
} }
// bmapping represents Get of Bucket or BTree.
type bmapping interface {
Get(context.Context, KEY) (interface{}, bool, error)
}
func TestBucket(t *testing.T) { func TestBucket(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})
...@@ -64,9 +76,27 @@ func TestBucket(t *testing.T) { ...@@ -64,9 +76,27 @@ func TestBucket(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
obj, ok := xobj.(*Bucket) obj, ok := xobj.(bmapping)
if !ok { if !ok {
t.Fatalf("%s: got %T; want Bucket", tt.oid, xobj) t.Fatalf("%s: got %T; want Bucket|BTree", tt.oid, xobj)
}
want := ""
switch tt.kind {
case kindBucket:
if _, ok = obj.(*Bucket); !ok {
want = "Bucket"
}
case kindBTree:
if _, ok = obj.(*BTree); !ok {
want = "BTree"
}
default:
panic(0)
}
if want != "" {
t.Fatalf("%s: got %T; want %s", tt.oid, obj, want)
} }
for _, kv := range tt.itemv { for _, kv := range tt.itemv {
...@@ -84,6 +114,9 @@ func TestBucket(t *testing.T) { ...@@ -84,6 +114,9 @@ func TestBucket(t *testing.T) {
if value != kv.value { if value != kv.value {
t.Errorf("get %v -> %v; want %v", kv.key, value, kv.value) t.Errorf("get %v -> %v; want %v", kv.key, value, kv.value)
} }
// XXX .next == nil
// XXX check keys, values directly (i.e. there is nothing else)
} }
} }
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"""generate test data for btree serialization tests""" """generate test data for btree serialization tests"""
from ZODB.DB import DB from ZODB.DB import DB
from BTrees.LOBTree import LOBucket from BTrees.LOBTree import LOBucket, LOBTree
from ZODB.utils import u64 from ZODB.utils import u64
import os, transaction import os, transaction
...@@ -40,6 +40,12 @@ def main(): ...@@ -40,6 +40,12 @@ def main():
root['b1'] = b1 = LOBucket([(10, 17)]) # 1k -> 1v root['b1'] = b1 = LOBucket([(10, 17)]) # 1k -> 1v
root['b2'] = b2 = LOBucket([(15, 1), (23, "hello")]) # 2k -> 2v root['b2'] = b2 = LOBucket([(15, 1), (23, "hello")]) # 2k -> 2v
root['B0'] = B0 = LOBTree() # empty btree
root['B1'] = B1 = LOBTree({5: 4}) # btree with 1 bucket (1kv)
root['B2'] = B2 = LOBTree({7: 3, 9: "world"}) # btree with 1 bucket (2kv)
root['B3'] = B3 = LOBTree(dict([(_, _) for _ in range(10000)]))
transaction.commit() transaction.commit()
with open("ztestdata_expect_test.go", "w") as f: with open("ztestdata_expect_test.go", "w") as f:
...@@ -49,9 +55,9 @@ def main(): ...@@ -49,9 +55,9 @@ def main():
emit("package btree\n") emit("package btree\n")
#emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n") #emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n")
emit("\nvar _bucketTestv = [...]testEntry{") def emititems(b):
for b in (b0, b1, b2): s = "testEntry{oid: %s, kind: %s, itemv: []kv{" \
s = "testEntry{oid: %s, itemv: []kv{" % u64(b._p_oid) % (u64(b._p_oid), "kind%s" % type(b).__name__[2:])
for k, v in b.items(): for k, v in b.items():
if isinstance(v, str): if isinstance(v, str):
v = qq(v) v = qq(v)
...@@ -63,8 +69,19 @@ def main(): ...@@ -63,8 +69,19 @@ def main():
s += "{%s, %s}, " % (k, v) s += "{%s, %s}, " % (k, v)
s += "}}," s += "}},"
emit("\t"+s) emit("\t"+s)
emit("\nvar _bucketTestv = [...]testEntry{")
for b in (b0, b1, b2, B0, B1, B2):
emititems(b)
emit("}") emit("}")
# emit("\nvar _btreeTestv = [...]testEntry{")
# for B in (B0, B1, B2): # XXX + B3
# emititems(B)
# emit("}")
# XXX B3
conn.close() conn.close()
db.close() db.close()
......
...@@ -3,7 +3,10 @@ package btree ...@@ -3,7 +3,10 @@ package btree
var _bucketTestv = [...]testEntry{ var _bucketTestv = [...]testEntry{
testEntry{oid: 1, itemv: []kv{}}, testEntry{oid: 6, kind: kindBucket, itemv: []kv{}},
testEntry{oid: 2, itemv: []kv{{10, int64(17)}, }}, testEntry{oid: 3, kind: kindBucket, itemv: []kv{{10, int64(17)}, }},
testEntry{oid: 3, itemv: []kv{{15, int64(1)}, {23, "hello"}, }}, testEntry{oid: 1, kind: kindBucket, itemv: []kv{{15, int64(1)}, {23, "hello"}, }},
testEntry{oid: 2, kind: kindBTree, itemv: []kv{}},
testEntry{oid: 7, kind: kindBTree, itemv: []kv{{5, int64(4)}, }},
testEntry{oid: 4, kind: kindBTree, itemv: []kv{{7, int64(3)}, {9, "world"}, }},
} }
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