mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
rearrange names, add more RemoteInterfaces to make tests pass again
This commit is contained in:
parent
30c16d6cb1
commit
23f663e12d
@ -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', '')
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user