Commit b04ae81a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d022326d
......@@ -117,7 +117,6 @@ def test_join_autostart():
# tDB is database/wcfs testing environment.
# XXX + tFile ?
class tDB:
def __init__(t):
t.root = testdb.dbopen()
......@@ -131,11 +130,17 @@ class tDB:
t._wc_zheadfh = open(t.wc.mountpoint + "/.wcfs/zhead")
t._wc_zheadv = []
# tracked tFiles
t.tracked = set()
def close(t):
for tf in t.tracked:
tf.close()
t._wc_zheadfh.close()
t.wc.close()
dbclose(t.root)
# commit commits transaction and remembers/returns committed transaction ID.
def commit(t):
# NOTE there is no clean way to retrieve tid of just committed transaction
......@@ -194,6 +199,25 @@ class tDB:
path = t.path(obj, at=at)
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.
# XXX not needed?
@func
......@@ -212,9 +236,16 @@ class tDB:
data += chunk
n -= len(chunk)
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
# assertFile asserts that wcfs file corresponding to zf has data blocks as specified.
# assertData asserts that file has data blocks as specified.
#
# Expected blocks may be given with size < zf.blksize. In such case they
# are implicitly appended with trailing zeros.
......@@ -222,32 +253,33 @@ class tDB:
# It also check file size and optionally mtime.
#
# XXX also check pagecache state?
def assertFile(t, zf, blkv, mtime=None, at=None):
assert isinstance(zf, ZBigFile)
st = t.stat(zf, at=at)
assert st.st_size == len(blkv)*zf.blksize
def assertData(t, blkv, mtime=None):
st = os.fstat(t.f.fileno())
assert st.st_size == len(blkv)*t.blksize
if mtime is not None:
assert st.st_mtime == tidtime(mtime)
data = t.read(zf, at=at)
assert len(data) == len(blkv)*zf.blksize
# XXX hack -> access mapped page
t.f.seek(0)
data = t.f.read()
assert len(data) == len(blkv)*t.blksize
for i, blk in enumerate(blkv):
assert len(blk) <= zf.blksize
blk += b'\0'*(zf.blksize - len(blk)) # trailing zeros
assert data[i*zf.blksize:(i+1)*zf.blksize] == blk, ("#blk: %d" % i)
assert len(blk) <= t.blksize
blk += b'\0'*(t.blksize - len(blk)) # trailing zeros
assert data[i*t.blksize:(i+1)*t.blksize] == blk, ("#blk: %d" % i)
# XXX assertCache for read blocks to be 1
# XXX text ...
# XXX parametrize zblk0, zblk1 XXX or just rely on tox?
@func
def test_wcfs():
t = tDB()
defer(t.close)
t.root['!file'] = nonfile = Persistent()
t.root['zfile'] = f = ZBigFile(blksize)
t.root['zfile'] = zf = ZBigFile(blksize)
tid1 = t.commit()
tid2 = t.commit()
......@@ -259,32 +291,34 @@ def test_wcfs():
t.stat(nonfile)
assert exc.value.errno == EINVAL
f = t.track(zf)
# file initially empty
_ = t.stat(f)
assert _.st_size == 0
assert _.st_mtime == tidtime(tid1)
f.assertCache([])
f.assertData ([], mtime=tid1)
# commit data to f and make sure we can see it on wcfs
# commit data to zf and make sure we can see it on wcfs
# use !wcfs mode so that we prepare data independently of wcfs code paths.
hole = 10
fh = f.fileh_open(_use_wcfs=False)
vma = fh.mmap(hole, 1) # 1 page at offset=10
zfh = zf.fileh_open(_use_wcfs=False)
vma = zfh.mmap(hole, 1) # 1 page at offset=10
s = b"hello world"
memcpy(vma, s)
t.commit()
t.wcsync() # sync wcfs to ZODB
# XXX assert cache = ø
t.assertFile(f, [b'']*hole + [s], mtime=t.head)
f.assertCache([0]*(hole+1)) # initially not cached
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.
tcommit1 = t.head
fh = f.fileh_open(_use_wcfs=False)
vma1 = fh.mmap(hole, 1)
vma2 = fh.mmap(hole+1, 1)
zfh = zf.fileh_open(_use_wcfs=False)
vma1 = zfh.mmap(hole, 1)
vma2 = zfh.mmap(hole+1, 1)
s1 = b"hello 123"
s2 = b"alpha"
memcpy(vma1,s1)
......@@ -294,12 +328,13 @@ def test_wcfs():
t.wcsync()
# f @head
# XXX assert cache
t.assertFile(f, [b'']*hole + [s1+b'ld', s2], mtime=t.head)
f.assertCache([1]*hole + [0,0])
f.assertData ([b'']*hole + [s1+b'ld', s2], mtime=t.head)
# f @tcommit1
# XXX assert cache
t.assertFile(f, [b'']*hole + [s], at=tcommit1) # XXX + mtime=tcommit1?
f1 = t.track(zf, at=tcommit1)
f1.assertCache([0]*hole + [1])
f1.assertData ([b'']*hole + [s]) # XXX + mtime=tcommit1?
# TODO pagecache state after loading (via mincore)
......
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