]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
added read and cross check to storage unit test, minor cleanups
authorRob Kinninmont <robk@allmydata.com>
Fri, 1 Dec 2006 09:21:11 +0000 (02:21 -0700)
committerRob Kinninmont <robk@allmydata.com>
Fri, 1 Dec 2006 09:21:11 +0000 (02:21 -0700)
allmydata/test/test_storage.py

index 33b19c20c8d7c8361bc95fb9851b5c49ffa96a02..fa9eafe04ea231bd2c5eede2426b3b8957097c8d 100644 (file)
@@ -21,6 +21,9 @@ class StorageTest(unittest.TestCase):
         return self.svc.startService()
 
     def test_create_bucket(self):
+        """
+        checks that the storage server can return bucket data accurately.
+        """
         vid = os.urandom(20)
         bnum = random.randint(0,100)
         data = os.urandom(random.randint(1024, 16384))
@@ -40,23 +43,50 @@ class StorageTest(unittest.TestCase):
         rssd.addCallback(create_bucket)
 
         def write_to_bucket(bucket):
-            def write_some(junk, bucket, bytes):
+            def write_some(junk, bytes):
                 return bucket.callRemote('write', data=bytes)
-            def finalise(junk, bucket):
+            def finalise(junk):
                 return bucket.callRemote('finalise')
             off1 = len(data) / 2
             off2 = 3 * len(data) / 4
             d = defer.succeed(None)
-            d.addCallback(write_some, bucket, data[:off1])
-            d.addCallback(write_some, bucket, data[off1:off2])
-            d.addCallback(write_some, bucket, data[off2:])
-            d.addCallback(finalise, bucket)
+            d.addCallback(write_some, data[:off1])
+            d.addCallback(write_some, data[off1:off2])
+            d.addCallback(write_some, data[off2:])
+            d.addCallback(finalise)
             return d
         rssd.addCallback(write_to_bucket)
 
+        def get_node_again(junk):
+            return self.tub.getReference(self.node.my_pburl)
+        rssd.addCallback(get_node_again)
+        rssd.addCallback(get_storageserver)
+
+        def get_bucket(storageserver):
+            return storageserver.callRemote('get_bucket', verifierid=vid)
+        rssd.addCallback(get_bucket)
+
+        def read_bucket(bucket):
+            def check_data(bytes_read):
+                self.failUnlessEqual(bytes_read, data)
+            d = bucket.callRemote('read')
+            d.addCallback(check_data)
+
+            def get_bucket_num(junk):
+                return bucket.callRemote('get_bucket_num')
+            d.addCallback(get_bucket_num)
+            def check_bucket_num(bucket_num):
+                self.failUnlessEqual(bucket_num, bnum)
+            d.addCallback(check_bucket_num)
+            return d
+        rssd.addCallback(read_bucket)
+
         return rssd
 
     def test_overwrite(self):
+        """
+        checks that the storage server rejects an attempt to write to much data
+        """
         vid = os.urandom(20)
         bnum = random.randint(0,100)
         data = os.urandom(random.randint(1024, 16384))
@@ -76,19 +106,19 @@ class StorageTest(unittest.TestCase):
         rssd.addCallback(create_bucket)
 
         def write_to_bucket(bucket):
-            def write_some(junk, bucket, bytes):
+            def write_some(junk, bytes):
                 return bucket.callRemote('write', data=bytes)
-            def finalise(junk, bucket):
+            def finalise(junk):
                 return bucket.callRemote('finalise')
             off1 = len(data) / 2
             off2 = 3 * len(data) / 4
             d = defer.succeed(None)
-            d.addCallback(write_some, bucket, data[:off1])
-            d.addCallback(write_some, bucket, data[off1:off2])
-            d.addCallback(write_some, bucket, data[off2:])
+            d.addCallback(write_some, data[:off1])
+            d.addCallback(write_some, data[off1:off2])
+            d.addCallback(write_some, data[off2:])
             # and then overwrite
-            d.addCallback(write_some, bucket, data[off1:off2])
-            d.addCallback(finalise, bucket)
+            d.addCallback(write_some, data[off1:off2])
+            d.addCallback(finalise)
             return d
         rssd.addCallback(write_to_bucket)