Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
18b3a2f3
Commit
18b3a2f3
authored
Feb 16, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
68590071
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
13 deletions
+58
-13
t/neo/storage/fs1/gen-testdata
t/neo/storage/fs1/gen-testdata
+18
-4
t/neo/storage/fs1/index_test.go
t/neo/storage/fs1/index_test.go
+27
-9
t/neo/storage/fs1/testdata_expect.go
t/neo/storage/fs1/testdata_expect.go
+13
-0
No files found.
t/neo/storage/fs1/gen-testdata
View file @
18b3a2f3
#!/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
()
t/neo/storage/fs1/index_test.go
View file @
18b3a2f3
...
@@ -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:
\n
have: %v
\n
want: %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:
\n
have: %v
\n
want: %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)
}
}
t/neo/storage/fs1/testdata_expect.go
0 → 100644
View file @
18b3a2f3
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
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment