From: Brian Warner Date: Wed, 18 Apr 2007 03:21:05 +0000 (-0700) Subject: storageserver: assert that blocks are written in-order, clean up tests a bit X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~75 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/frontends?a=commitdiff_plain;h=008e418523d5c89d56316399c8df293ff70dbef8;p=tahoe-lafs%2Ftahoe-lafs.git storageserver: assert that blocks are written in-order, clean up tests a bit --- 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)