]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_system: add test coverage for immutable download.ConsumerAdapter, remove debug...
authorBrian Warner <warner@allmydata.com>
Mon, 6 Oct 2008 22:50:37 +0000 (15:50 -0700)
committerBrian Warner <warner@allmydata.com>
Mon, 6 Oct 2008 22:50:37 +0000 (15:50 -0700)
src/allmydata/immutable/download.py
src/allmydata/immutable/filenode.py
src/allmydata/test/test_system.py

index f8d2a00a12e015ea0b97dcf4bd048577785ddab1..80b9ce65c0265ef20bb18b45dfd475663c7c573c 100644 (file)
@@ -1046,13 +1046,13 @@ class ConsumerAdapter:
         self._when_finished = observer.OneShotObserverList()
 
     def when_finished(self):
+        # I think this is unused, along with self._when_finished . But I need
+        # to trace the error paths to be sure.
         return self._when_finished.when_fired()
 
     def registerProducer(self, producer, streaming):
-        print "REG"
         self._consumer.registerProducer(producer, streaming)
     def unregisterProducer(self):
-        print "UNREG"
         self._consumer.unregisterProducer()
 
     def open(self, size):
index a1a66128ef171795f3606bac94ab6f60dbe9b148..93ba404738d379b4a396a9de402e401e95aecad5 100644 (file)
@@ -92,10 +92,8 @@ class FileNode(ImmutableFileNode):
 class LiteralProducer:
     implements(IPushProducer)
     def resumeProducing(self):
-        print "LIT RESUME"
         pass
     def stopProducing(self):
-        print "LIT STOP"
         pass
 
 class LiteralFileNode(ImmutableFileNode):
index 89ec26ee65cb8c11f39010471edd66b4d41783e3..ad614c3842e5e3dd9fabef4e5a9c876674d56e5a 100644 (file)
@@ -1,10 +1,12 @@
 from base64 import b32encode
 import os, sys, time, re, simplejson, urllib
 from cStringIO import StringIO
+from zope.interface import implements
 from twisted.trial import unittest
 from twisted.internet import defer
 from twisted.internet import threads # CLI tests use deferToThread
 from twisted.internet.error import ConnectionDone, ConnectionLost
+from twisted.internet.interfaces import IConsumer, IPushProducer
 import allmydata
 from allmydata import uri, storage, offloaded
 from allmydata.immutable import download, upload, filenode
@@ -41,6 +43,21 @@ class CountingDataUploadable(upload.Data):
                 self.interrupt_after_d.callback(self)
         return upload.Data.read(self, length)
 
+class GrabEverythingConsumer:
+    implements(IConsumer)
+
+    def __init__(self):
+        self.contents = ""
+
+    def registerProducer(self, producer, streaming):
+        assert streaming
+        assert IPushProducer.providedBy(producer)
+
+    def write(self, data):
+        self.contents += data
+
+    def unregisterProducer(self):
+        pass
 
 class SystemTest(SystemTestMixin, unittest.TestCase):
 
@@ -159,6 +176,14 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
             self.failUnlessEqual(newdata, DATA)
         d.addCallback(_download_to_filehandle_done)
 
+        consumer = GrabEverythingConsumer()
+        ct = download.ConsumerAdapter(consumer)
+        d.addCallback(lambda res:
+                      self.downloader.download(self.uri, ct))
+        def _download_to_consumer_done(ign):
+            self.failUnlessEqual(consumer.contents, DATA)
+        d.addCallback(_download_to_consumer_done)
+
         def _download_nonexistent_uri(res):
             baduri = self.mangle_uri(self.uri)
             log.msg("about to download non-existent URI", level=log.UNUSUAL,