Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
b04ae81a
Commit
b04ae81a
authored
Mar 15, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d022326d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
29 deletions
+64
-29
wcfs/wcfs_test.py
wcfs/wcfs_test.py
+64
-29
No files found.
wcfs/wcfs_test.py
View file @
b04ae81a
...
@@ -117,7 +117,6 @@ def test_join_autostart():
...
@@ -117,7 +117,6 @@ def test_join_autostart():
# tDB is database/wcfs testing environment.
# tDB is database/wcfs testing environment.
# XXX + tFile ?
class
tDB
:
class
tDB
:
def
__init__
(
t
):
def
__init__
(
t
):
t
.
root
=
testdb
.
dbopen
()
t
.
root
=
testdb
.
dbopen
()
...
@@ -131,11 +130,17 @@ class tDB:
...
@@ -131,11 +130,17 @@ class tDB:
t
.
_wc_zheadfh
=
open
(
t
.
wc
.
mountpoint
+
"/.wcfs/zhead"
)
t
.
_wc_zheadfh
=
open
(
t
.
wc
.
mountpoint
+
"/.wcfs/zhead"
)
t
.
_wc_zheadv
=
[]
t
.
_wc_zheadv
=
[]
# tracked tFiles
t
.
tracked
=
set
()
def
close
(
t
):
def
close
(
t
):
for
tf
in
t
.
tracked
:
tf
.
close
()
t
.
_wc_zheadfh
.
close
()
t
.
_wc_zheadfh
.
close
()
t
.
wc
.
close
()
t
.
wc
.
close
()
dbclose
(
t
.
root
)
dbclose
(
t
.
root
)
# commit commits transaction and remembers/returns committed transaction ID.
# commit commits transaction and remembers/returns committed transaction ID.
def
commit
(
t
):
def
commit
(
t
):
# NOTE there is no clean way to retrieve tid of just committed transaction
# NOTE there is no clean way to retrieve tid of just committed transaction
...
@@ -194,6 +199,25 @@ class tDB:
...
@@ -194,6 +199,25 @@ class tDB:
path
=
t
.
path
(
obj
,
at
=
at
)
path
=
t
.
path
(
obj
,
at
=
at
)
return
open
(
path
)
return
open
(
path
)
# track starts to track wcfs file corresponding to zf@at.
# see returned tFile for details.
def
track
(
t
,
zf
,
at
=
None
):
tf
=
tFile
(
t
,
zf
,
at
=
at
)
t
.
tracked
.
add
(
tf
)
return
tf
# tFile is testing environment for one bigfile on wcfs.
class
tFile
:
def
__init__
(
t
,
tdb
,
zf
,
at
=
None
):
assert
isinstance
(
zf
,
ZBigFile
)
t
.
tdb
=
tdb
t
.
f
=
tdb
.
open
(
zf
,
at
=
at
)
t
.
blksize
=
zf
.
blksize
def
close
(
t
):
t
.
f
.
close
()
"""
# readblk reads ZBigFile[blk] from wcfs.
# readblk reads ZBigFile[blk] from wcfs.
# XXX not needed?
# XXX not needed?
@func
@func
...
@@ -212,9 +236,16 @@ class tDB:
...
@@ -212,9 +236,16 @@ class tDB:
data += chunk
data += chunk
n -= len(chunk)
n -= len(chunk)
return data
return data
"""
# assertCache asserts state of OS file cache.
#
# incorev is [] of 1/0 representing whether block data is present or not.
def
assertCache
(
t
,
incorev
):
pass
# TODO
# assert
File asserts that wcfs file corresponding to zf
has data blocks as specified.
# assert
Data asserts that file
has data blocks as specified.
#
#
# Expected blocks may be given with size < zf.blksize. In such case they
# Expected blocks may be given with size < zf.blksize. In such case they
# are implicitly appended with trailing zeros.
# are implicitly appended with trailing zeros.
...
@@ -222,32 +253,33 @@ class tDB:
...
@@ -222,32 +253,33 @@ class tDB:
# It also check file size and optionally mtime.
# It also check file size and optionally mtime.
#
#
# XXX also check pagecache state?
# XXX also check pagecache state?
def
assertFile
(
t
,
zf
,
blkv
,
mtime
=
None
,
at
=
None
):
def
assertData
(
t
,
blkv
,
mtime
=
None
):
assert
isinstance
(
zf
,
ZBigFile
)
st
=
os
.
fstat
(
t
.
f
.
fileno
())
assert
st
.
st_size
==
len
(
blkv
)
*
t
.
blksize
st
=
t
.
stat
(
zf
,
at
=
at
)
assert
st
.
st_size
==
len
(
blkv
)
*
zf
.
blksize
if
mtime
is
not
None
:
if
mtime
is
not
None
:
assert
st
.
st_mtime
==
tidtime
(
mtime
)
assert
st
.
st_mtime
==
tidtime
(
mtime
)
data
=
t
.
read
(
zf
,
at
=
at
)
# XXX hack -> access mapped page
assert
len
(
data
)
==
len
(
blkv
)
*
zf
.
blksize
t
.
f
.
seek
(
0
)
data
=
t
.
f
.
read
()
assert
len
(
data
)
==
len
(
blkv
)
*
t
.
blksize
for
i
,
blk
in
enumerate
(
blkv
):
for
i
,
blk
in
enumerate
(
blkv
):
assert
len
(
blk
)
<=
zf
.
blksize
assert
len
(
blk
)
<=
t
.
blksize
blk
+=
b'
\
0
'
*
(
zf
.
blksize
-
len
(
blk
))
# trailing zeros
blk
+=
b'
\
0
'
*
(
t
.
blksize
-
len
(
blk
))
# trailing zeros
assert
data
[
i
*
zf
.
blksize
:(
i
+
1
)
*
zf
.
blksize
]
==
blk
,
(
"#blk: %d"
%
i
)
assert
data
[
i
*
t
.
blksize
:(
i
+
1
)
*
t
.
blksize
]
==
blk
,
(
"#blk: %d"
%
i
)
# XXX assertCache for read blocks to be 1
# XXX text ...
# XXX text ...
# XXX parametrize zblk0, zblk1 XXX or just rely on tox?
@
func
@
func
def
test_wcfs
():
def
test_wcfs
():
t
=
tDB
()
t
=
tDB
()
defer
(
t
.
close
)
defer
(
t
.
close
)
t
.
root
[
'!file'
]
=
nonfile
=
Persistent
()
t
.
root
[
'!file'
]
=
nonfile
=
Persistent
()
t
.
root
[
'zfile'
]
=
f
=
ZBigFile
(
blksize
)
t
.
root
[
'zfile'
]
=
z
f
=
ZBigFile
(
blksize
)
tid1
=
t
.
commit
()
tid1
=
t
.
commit
()
tid2
=
t
.
commit
()
tid2
=
t
.
commit
()
...
@@ -259,32 +291,34 @@ def test_wcfs():
...
@@ -259,32 +291,34 @@ def test_wcfs():
t
.
stat
(
nonfile
)
t
.
stat
(
nonfile
)
assert
exc
.
value
.
errno
==
EINVAL
assert
exc
.
value
.
errno
==
EINVAL
f
=
t
.
track
(
zf
)
# file initially empty
# file initially empty
_
=
t
.
stat
(
f
)
f
.
assertCache
([])
assert
_
.
st_size
==
0
f
.
assertData
([],
mtime
=
tid1
)
assert
_
.
st_mtime
==
tidtime
(
tid1
)
# commit data to f and make sure we can see it on wcfs
# commit data to
z
f and make sure we can see it on wcfs
# use !wcfs mode so that we prepare data independently of wcfs code paths.
# use !wcfs mode so that we prepare data independently of wcfs code paths.
hole
=
10
hole
=
10
fh
=
f
.
fileh_open
(
_use_wcfs
=
False
)
zfh
=
z
f
.
fileh_open
(
_use_wcfs
=
False
)
vma
=
fh
.
mmap
(
hole
,
1
)
# 1 page at offset=10
vma
=
zfh
.
mmap
(
hole
,
1
)
# 1 page at offset=10
s
=
b"hello world"
s
=
b"hello world"
memcpy
(
vma
,
s
)
memcpy
(
vma
,
s
)
t
.
commit
()
t
.
commit
()
t
.
wcsync
()
# sync wcfs to ZODB
t
.
wcsync
()
# sync wcfs to ZODB
# XXX assert cache = ø
f
.
assertCache
([
0
]
*
(
hole
+
1
))
# initially not cached
t
.
assertFile
(
f
,
[
b''
]
*
hole
+
[
s
],
mtime
=
t
.
head
)
f
.
assertData
([
b''
]
*
hole
+
[
s
],
mtime
=
t
.
head
)
# XXX assertCache all present?
# commit data again and make sure we can see both latest and snapshotted states.
# commit data again and make sure we can see both latest and snapshotted states.
tcommit1
=
t
.
head
tcommit1
=
t
.
head
fh
=
f
.
fileh_open
(
_use_wcfs
=
False
)
zfh
=
z
f
.
fileh_open
(
_use_wcfs
=
False
)
vma1
=
fh
.
mmap
(
hole
,
1
)
vma1
=
z
fh
.
mmap
(
hole
,
1
)
vma2
=
fh
.
mmap
(
hole
+
1
,
1
)
vma2
=
z
fh
.
mmap
(
hole
+
1
,
1
)
s1
=
b"hello 123"
s1
=
b"hello 123"
s2
=
b"alpha"
s2
=
b"alpha"
memcpy
(
vma1
,
s1
)
memcpy
(
vma1
,
s1
)
...
@@ -294,12 +328,13 @@ def test_wcfs():
...
@@ -294,12 +328,13 @@ def test_wcfs():
t
.
wcsync
()
t
.
wcsync
()
# f @head
# f @head
# XXX assert cache
f
.
assertCache
([
1
]
*
hole
+
[
0
,
0
])
t
.
assertFile
(
f
,
[
b''
]
*
hole
+
[
s1
+
b'ld'
,
s2
],
mtime
=
t
.
head
)
f
.
assertData
(
[
b''
]
*
hole
+
[
s1
+
b'ld'
,
s2
],
mtime
=
t
.
head
)
# f @tcommit1
# f @tcommit1
# XXX assert cache
f1
=
t
.
track
(
zf
,
at
=
tcommit1
)
t
.
assertFile
(
f
,
[
b''
]
*
hole
+
[
s
],
at
=
tcommit1
)
# XXX + mtime=tcommit1?
f1
.
assertCache
([
0
]
*
hole
+
[
1
])
f1
.
assertData
([
b''
]
*
hole
+
[
s
])
# XXX + mtime=tcommit1?
# TODO pagecache state after loading (via mincore)
# TODO pagecache state after loading (via mincore)
...
...
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