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
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
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', '')
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):
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):
return Nothing()
+class RIBucketReader(RemoteInterface):
+ def get_bucket_num():
+ return int
+
+ def read():
+ return ShareData
+
+
from allmydata.bucketstore import BucketStore
from zope.interface import implements
from allmydata.interfaces import RIStorageServer
+from allmydata.util import idlib
class BucketAlreadyExistsError(Exception):
pass
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):
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)
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)
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())