From 008e418523d5c89d56316399c8df293ff70dbef8 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 17 Apr 2007 20:21:05 -0700 Subject: [PATCH] storageserver: assert that blocks are written in-order, clean up tests a bit --- src/allmydata/storageserver.py | 3 +++ src/allmydata/test/test_storage.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/allmydata/storageserver.py b/src/allmydata/storageserver.py index 67def368..1cb19e5b 100644 --- a/src/allmydata/storageserver.py +++ b/src/allmydata/storageserver.py @@ -30,6 +30,7 @@ class BucketWriter(Referenceable): self.finalhome = finalhome self.blocksize = blocksize self.closed = False + self._next_segnum = 0 fileutil.make_dirs(incominghome) self._write_file('blocksize', str(blocksize)) @@ -42,6 +43,8 @@ class BucketWriter(Referenceable): # last one may be short, and we don't know the total number of # segments so we can't tell which is which. assert len(data) <= self.blocksize + assert segmentnum == self._next_segnum # must write in sequence + self._next_segnum = segmentnum + 1 f = fileutil.open_or_create(os.path.join(self.incominghome, 'data')) f.seek(self.blocksize*segmentnum) f.write(data) diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 39d1bd14..31063a70 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -7,23 +7,23 @@ from allmydata.util import fileutil class Storage(unittest.TestCase): def make_workdir(self, name): - tmpdir = os.path.join("test_storage", "Storage", "tmp", name) basedir = os.path.join("test_storage", "Storage", name) - fileutil.make_dirs(tmpdir) + incoming = os.path.join(basedir, "tmp", "bucket") + final = os.path.join(basedir, "bucket") fileutil.make_dirs(basedir) - return tmpdir, basedir + return incoming, final def test_create(self): - tmpdir, basedir = self.make_workdir("test_create") - bw = storageserver.BucketWriter(tmpdir, basedir, 25) + incoming, final = self.make_workdir("test_create") + bw = storageserver.BucketWriter(incoming, final, 25) bw.remote_put_block(0, "a"*25) bw.remote_put_block(1, "b"*25) bw.remote_put_block(2, "c"*7) # last block may be short bw.remote_close() def test_readwrite(self): - tmpdir, basedir = self.make_workdir("test_readwrite") - bw = storageserver.BucketWriter(tmpdir, basedir, 25) + incoming, final = self.make_workdir("test_readwrite") + bw = storageserver.BucketWriter(incoming, final, 25) bw.remote_put_block(0, "a"*25) bw.remote_put_block(1, "b"*25) bw.remote_put_block(2, "c"*7) # last block may be short @@ -32,7 +32,7 @@ class Storage(unittest.TestCase): bw.remote_close() # now read from it - br = storageserver.BucketReader(basedir) + br = storageserver.BucketReader(final) self.failUnlessEqual(br.remote_get_block(0), "a"*25) self.failUnlessEqual(br.remote_get_block(1), "b"*25) self.failUnlessEqual(br.remote_get_block(2), "c"*7) -- 2.45.2