]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
rearrange names, add more RemoteInterfaces to make tests pass again
authorBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 00:25:57 +0000 (17:25 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 00:25:57 +0000 (17:25 -0700)
allmydata/bucketstore.py
allmydata/interfaces.py
allmydata/storageserver.py
allmydata/test/test_storage.py

index b8c13d8ff4165df4317e98d9f31c4707d6d070c8..ddd7cfc922425e7db71b11978c7815b6c319ae81 100644 (file)
@@ -5,7 +5,7 @@ from twisted.application import service
 from twisted.python.failure import Failure
 from allmydata.util import idlib
 from zope.interface import implements
-from allmydata.interfaces import RIBucketWriter
+from allmydata.interfaces import RIBucketWriter, RIBucketReader
 
 from amdlib.util.assertutil import precondition, _assert
 
@@ -59,10 +59,12 @@ class Lease(Referenceable):
     def remote_write(self, data):
         self._bucket.write(data)
 
-    def remote_finalise(self):
-        self._bucket.finalise()
+    def remote_close(self):
+        self._bucket.close()
 
 class BucketReader(Referenceable):
+    implements(RIBucketReader)
+
     def __init__(self, bucket):
         self._bucket = bucket
 
@@ -112,7 +114,7 @@ class WriteBucket(Bucket):
         self._data.flush()
         self._bytes_written += len(data)
 
-    def finalise(self):
+    def close(self):
         precondition(self._bytes_written == self._size)
         self._data.close()
         self._write_attr('closed', '')
index dd45a28a5c41f43c69780436517bcb6fd40e5bb5..108998558626c124262aea288f83690cf0ef8ed6 100644 (file)
@@ -6,11 +6,12 @@ Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash
 PBURL = StringConstraint(150)
 Verifierid = StringConstraint(20)
 ShareData = StringConstraint(20000)
-# these three are here because Foolscap does not yet support the kind of
+# these four are here because Foolscap does not yet support the kind of
 # restriction I really want to apply to these.
 RIClient_ = Any()
 Referenceable_ = Any()
 RIBucketWriter_ = Any()
+RIBucketReader_ = Any()
 
 class RIQueenRoster(RemoteInterface):
     def hello(nodeid=Nodeid, node=RIClient_, pburl=PBURL):
@@ -28,7 +29,8 @@ class RIStorageServer(RemoteInterface):
     def allocate_bucket(verifierid=Verifierid, bucket_num=int, size=int,
                         leaser=Nodeid):
         return RIBucketWriter_
-
+    def get_bucket(verifierid=Verifierid):
+        return RIBucketReader_
 
 class RIBucketWriter(RemoteInterface):
     def write(data=ShareData):
@@ -41,3 +43,11 @@ class RIBucketWriter(RemoteInterface):
         return Nothing()
 
 
+class RIBucketReader(RemoteInterface):
+    def get_bucket_num():
+        return int
+
+    def read():
+        return ShareData
+
+
index 951fed6f72427db2aa3d251234ef6a81d213a6df..8bd2514256da4c0f0045d1bcb6582f9c2d3dbe6c 100644 (file)
@@ -6,6 +6,7 @@ from twisted.application import service
 from allmydata.bucketstore import BucketStore
 from zope.interface import implements
 from allmydata.interfaces import RIStorageServer
+from allmydata.util import idlib
 
 class BucketAlreadyExistsError(Exception):
     pass
@@ -24,7 +25,8 @@ class StorageServer(service.MultiService, Referenceable):
     def remote_allocate_bucket(self, verifierid, bucket_num, size, leaser):
         if self._bucketstore.has_bucket(verifierid):
             raise BucketAlreadyExistsError()
-        lease = self._bucketstore.allocate_bucket(verifierid, bucket_num, size, leaser)
+        lease = self._bucketstore.allocate_bucket(verifierid, bucket_num, size,
+                                                  idlib.b2a(leaser))
         return lease
 
     def remote_get_bucket(self, verifierid):
index c61adc12aa0a95fe5c94aec5855be240b044a8d3..05ecb22cb5a08a3a0dcaad61c9fbba54752a946b 100644 (file)
@@ -46,7 +46,7 @@ class StorageTest(unittest.TestCase):
             def write_some(junk, bytes):
                 return bucket.callRemote('write', data=bytes)
             def finalise(junk):
-                return bucket.callRemote('finalise')
+                return bucket.callRemote('close')
             off1 = len(data) / 2
             off2 = 3 * len(data) / 4
             d = defer.succeed(None)
@@ -109,7 +109,7 @@ class StorageTest(unittest.TestCase):
             def write_some(junk, bytes):
                 return bucket.callRemote('write', data=bytes)
             def finalise(junk):
-                return bucket.callRemote('finalise')
+                return bucket.callRemote('close')
             off1 = len(data) / 2
             off2 = 3 * len(data) / 4
             d = defer.succeed(None)
@@ -122,12 +122,23 @@ class StorageTest(unittest.TestCase):
             return d
         rssd.addCallback(write_to_bucket)
 
-        def should_fail(f):
-            f.trap(AssertionError)
-
-        rssd.addCallbacks(self.fail, should_fail)
+        self.deferredShouldFail(rssd, ftype=AssertionError)
         return rssd
 
+    def deferredShouldFail(self, d, ftype=None, checker=None):
+
+        def _worked(res):
+            self.fail("hey, this was supposed to fail, not return %s" % res)
+        if not ftype and not checker:
+            d.addCallbacks(_worked,
+                           lambda f: None)
+        elif ftype and not checker:
+            d.addCallbacks(_worked,
+                           lambda f: f.trap(ftype) or None)
+        else:
+            d.addCallbacks(_worked,
+                           checker)
+
     def tearDown(self):
         d = self.svc.stopService()
         d.addCallback(lambda res: flushEventualQueue())