From: Brian Warner Date: Sat, 2 Dec 2006 02:17:26 +0000 (-0700) Subject: change bucket writer protocol, give Encoder a RemoteReference instead of a file-like... X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~500 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/frontends/flags?a=commitdiff_plain;h=18d8911c51a17ea2c90ab014c632d7565450f079;p=tahoe-lafs%2Ftahoe-lafs.git change bucket writer protocol, give Encoder a RemoteReference instead of a file-like object --- diff --git a/allmydata/test/test_upload.py b/allmydata/test/test_upload.py index efcbd74e..349133d5 100644 --- a/allmydata/test/test_upload.py +++ b/allmydata/test/test_upload.py @@ -1,9 +1,36 @@ from twisted.trial import unittest from twisted.internet import defer +from cStringIO import StringIO from allmydata import upload +class StringBucketProxy: + # This is for unit tests: make a StringIO look like a RIBucketWriter. + + def __init__(self): + self.data = StringIO() + self.size = None + self.done = False + + def callRemote(self, methname, **kwargs): + if methname == "write": + return defer.maybeDeferred(self.write, **kwargs) + elif methname == "set_size": + return defer.maybeDeferred(self.set_size, **kwargs) + elif methname == "close": + return defer.maybeDeferred(self.close, **kwargs) + else: + return defer.fail(NameError("no such method named %s" % methname)) + + def write(self, data): + self.data.write(data) + def set_size(self, size): + self.size = size + def close(self): + self.done = True + + class FakePeer: def __init__(self, peerid, response): self.peerid = peerid @@ -55,9 +82,7 @@ class NextPeer(unittest.TestCase): def compare_landlords(self, u, c, expected): exp = [(peerid, bucketnum, c.peers[peerid]) for peerid, bucketnum in expected] - landlords = [(peerid, bucketnum, proxy.remote_bucket) - for peerid, bucketnum, proxy in u.landlords] - self.failUnlessEqual(landlords, exp) + self.failUnlessEqual(u.landlords, exp) def test_0(self): c = FakeClient([]) diff --git a/allmydata/upload.py b/allmydata/upload.py index f9f91567..ae659c03 100644 --- a/allmydata/upload.py +++ b/allmydata/upload.py @@ -13,31 +13,6 @@ class HaveAllPeersError(Exception): class TooFullError(Exception): pass -class WriterProxy: - # make this look like a writable file - def __init__(self, remote_bucket): - self.remote_bucket = remote_bucket - self.good = True - - def _broken(self, why): - self.good = False - # do something else here - return why - - def write(self, data): - d = self.remote_bucket.callRemote("write", data=data) - d.addErrback(self._broken) - - def seek(self, offset, whence=0): - d = self.remote_bucket.callRemote("seek", offset=offset, whence=whence) - d.addErrback(self._broken) - - def close(self): - if self._broken: - raise SomethingBrokeError() - d = self.remote_bucket.callRemote("close") - d.addErrback(self._broken) - class Uploader: debug = False @@ -98,8 +73,7 @@ class Uploader: def _allocate_response(bucket): if self.debug: print " peerid %s will grant us a lease" % peerid - writer = WriterProxy(bucket) - self.landlords.append( (peerid, bucket_num, writer) ) + self.landlords.append( (peerid, bucket_num, bucket) ) self.goodness_points += 1 if self.goodness_points >= self.target_goodness: if self.debug: print " we're done!"