]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
storageserver: assert that blocks are written in-order, clean up tests a bit
authorBrian Warner <warner@allmydata.com>
Wed, 18 Apr 2007 03:21:05 +0000 (20:21 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 18 Apr 2007 03:21:05 +0000 (20:21 -0700)
src/allmydata/storageserver.py
src/allmydata/test/test_storage.py

index 67def3680c557f0b1f251eaed50705cb56aee0a5..1cb19e5b4dfd76d3c0d058be9a7b4704fdffb49a 100644 (file)
@@ -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)
index 39d1bd1423d83cab416ff4c955f0c645ebc60b0b..31063a70095b2a702e38ce557509560f7067893e 100644 (file)
@@ -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)