From: Brian Warner Date: Sun, 3 Dec 2006 00:25:57 +0000 (-0700) Subject: rearrange names, add more RemoteInterfaces to make tests pass again X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~495 X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=23f663e12dbe87622ca75bf013244c7bd056ec82;p=tahoe-lafs%2Ftahoe-lafs.git rearrange names, add more RemoteInterfaces to make tests pass again --- diff --git a/allmydata/bucketstore.py b/allmydata/bucketstore.py index b8c13d8f..ddd7cfc9 100644 --- a/allmydata/bucketstore.py +++ b/allmydata/bucketstore.py @@ -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', '') diff --git a/allmydata/interfaces.py b/allmydata/interfaces.py index dd45a28a..10899855 100644 --- a/allmydata/interfaces.py +++ b/allmydata/interfaces.py @@ -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 + + diff --git a/allmydata/storageserver.py b/allmydata/storageserver.py index 951fed6f..8bd25142 100644 --- a/allmydata/storageserver.py +++ b/allmydata/storageserver.py @@ -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): diff --git a/allmydata/test/test_storage.py b/allmydata/test/test_storage.py index c61adc12..05ecb22c 100644 --- a/allmydata/test/test_storage.py +++ b/allmydata/test/test_storage.py @@ -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())