]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
change bucket writer protocol, give Encoder a RemoteReference instead of a file-like...
authorBrian Warner <warner@lothar.com>
Sat, 2 Dec 2006 02:17:26 +0000 (19:17 -0700)
committerBrian Warner <warner@lothar.com>
Sat, 2 Dec 2006 02:17:26 +0000 (19:17 -0700)
allmydata/test/test_upload.py
allmydata/upload.py

index efcbd74e6d3278425fafe668c631a54cec946e36..349133d5664bd591c2d77ae4876a1d1a65952430 100644 (file)
@@ -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([])
index f9f915677b0dce853fcfd216024b9da64c107c2a..ae659c03cc2066519c3bd4af1525401b526846cd 100644 (file)
@@ -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!"