Commit 18b3a2f3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 68590071
#!/usr/bin/env python2 #!/usr/bin/env python2
"""generate reference index and database for tests""" """generate reference database and index for tests"""
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB import DB from ZODB import DB
...@@ -11,9 +11,12 @@ import time ...@@ -11,9 +11,12 @@ import time
import random import random
import logging import logging
# convert numeric oid to str # convert numeric oid to/from str
def oid(v): def oid(num):
return struct.pack('>Q', v) return struct.pack('>Q', num)
def oidN(packed):
return struct.unpack('>Q', packed)[0]
# make time.time() predictable # make time.time() predictable
_xtime = time.mktime(time.strptime("04 Jan 1979", "%d %b %Y")) _xtime = time.mktime(time.strptime("04 Jan 1979", "%d %b %Y"))
...@@ -71,6 +74,17 @@ def main(): ...@@ -71,6 +74,17 @@ def main():
db.close() db.close()
stor.close() stor.close()
# dump to go what to expect
with open("testdata_expect.go", "w") as f:
def emit(v):
print >>f, v
emit("package fs1\n")
emit("const _1fs_indexTopPos = %i" % stor._pos)
emit("var _1fs_indexEntryv = [...]indexEntry{")
for k, v in stor._index.iteritems():
emit("\t{%8i, %8i}," % (oidN(k), v))
emit("}")
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -160,6 +160,18 @@ func TestIndexLookup(t *testing.T) { ...@@ -160,6 +160,18 @@ func TestIndexLookup(t *testing.T) {
} }
} }
func checkIndexEqual(t *testing.T, subject string, topPos1, topPos2 int64, fsi1, fsi2 *fsIndex) {
if topPos1 != topPos2 {
t.Errorf("%s: topPos mismatch: %v ; want %v", subject, topPos1, topPos2)
}
if !treeEqual(fsi1.Tree, fsi2.Tree) {
t.Errorf("%s: trees mismatch:\nhave: %v\nwant: %v", subject, fsi1.Tree.Dump(), fsi2.Tree.Dump())
//t.Errorf("index load: trees mismatch:\nhave: %v\nwant: %v", treeString(fsi2.Tree), treeString(fsi.Tree))
}
}
func TestIndexSaveLoad(t *testing.T) { func TestIndexSaveLoad(t *testing.T) {
workdir, err := ioutil.TempDir("", "t-index") workdir, err := ioutil.TempDir("", "t-index")
if err != nil { if err != nil {
...@@ -181,20 +193,26 @@ func TestIndexSaveLoad(t *testing.T) { ...@@ -181,20 +193,26 @@ func TestIndexSaveLoad(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if topPos2 != topPos { checkIndexEqual(t, "index load", topPos2, topPos, fsi2, fsi)
t.Errorf("index load: topPos mismatch: %v ; want %v", topPos2, topPos)
}
if !treeEqual(fsi2.Tree, fsi.Tree) {
t.Errorf("index load: trees mismatch:\nhave: %v\nwant: %v", fsi2.Tree.Dump(), fsi.Tree.Dump())
//t.Errorf("index load: trees mismatch:\nhave: %v\nwant: %v", treeString(fsi2.Tree), treeString(fsi.Tree))
}
// TODO check with // TODO check with
// {0xb000000000000000, 0x7fffffffffffffff}, // will cause 'entry position too large' // {0xb000000000000000, 0x7fffffffffffffff}, // will cause 'entry position too large'
} }
// test that we can correctly load index data as saved by zodb/py
func TestIndexLoadFromPy(t *testing.T) {
topPosPy, fsiPy, err := LoadIndexFile("testdata/1.fs.index")
if err != nil {
t.Fatal(err)
}
fsiExpect := fsIndexNew()
setIndex(fsiExpect, _1fs_indexEntryv[:])
checkIndexEqual(t, "index load", topPosPy, _1fs_indexTopPos, fsiPy, fsiExpect)
}
var havePyZODB = false var havePyZODB = false
func init() { func init() {
cmd := exec.Command("python2", "-c", "import ZODB") cmd := exec.Command("python2", "-c", "import ZODB")
...@@ -203,5 +221,5 @@ func init() { ...@@ -203,5 +221,5 @@ func init() {
havePyZODB = true havePyZODB = true
} }
println("havePyZODB:", havePyZODB) //println("havePyZODB:", havePyZODB)
} }
package fs1
const _1fs_indexTopPos = 8917
var _1fs_indexEntryv = [...]indexEntry{
{ 0, 5029},
{ 1, 7211},
{ 2, 8099},
{ 3, 8691},
{ 4, 8543},
{ 5, 7359},
{ 6, 8839},
{ 7, 7507},
}
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