示例#1
0
    def test_push_producer_feedback(self):
        string_file = BlockingStringWrite()
        consumer = BackgroundFileConsumer(string_file, reactor=reactor)

        try:
            producer = NonCallableMock(
                spec_set=["pauseProducing", "resumeProducing"])

            resume_deferred = defer.Deferred()
            producer.resumeProducing.side_effect = lambda: resume_deferred.callback(
                None)

            consumer.registerProducer(producer, True)

            number_writes = 0
            with string_file.write_lock:
                for _ in range(consumer._PAUSE_ON_QUEUE_SIZE):
                    consumer.write("Foo")
                    number_writes += 1

                producer.pauseProducing.assert_called_once()

            yield string_file.wait_for_n_writes(number_writes)

            yield resume_deferred
            producer.resumeProducing.assert_called_once()
        finally:
            consumer.unregisterProducer()

        yield consumer.wait()

        self.assertTrue(string_file.closed)
示例#2
0
    def test_push_producer_feedback(self):
        string_file = BlockingStringWrite()
        consumer = BackgroundFileConsumer(string_file)

        try:
            producer = NonCallableMock(spec_set=["pauseProducing", "resumeProducing"])

            resume_deferred = defer.Deferred()
            producer.resumeProducing.side_effect = lambda: resume_deferred.callback(None)

            consumer.registerProducer(producer, True)

            number_writes = 0
            with string_file.write_lock:
                for _ in range(consumer._PAUSE_ON_QUEUE_SIZE):
                    consumer.write("Foo")
                    number_writes += 1

                producer.pauseProducing.assert_called_once()

            yield string_file.wait_for_n_writes(number_writes)

            yield resume_deferred
            producer.resumeProducing.assert_called_once()
        finally:
            consumer.unregisterProducer()

        yield consumer.wait()

        self.assertTrue(string_file.closed)
示例#3
0
    def test_pull_consumer(self):
        string_file = StringIO()
        consumer = BackgroundFileConsumer(string_file, reactor=reactor)

        try:
            producer = DummyPullProducer()

            yield producer.register_with_consumer(consumer)

            yield producer.write_and_wait("Foo")

            self.assertEqual(string_file.getvalue(), "Foo")

            yield producer.write_and_wait("Bar")

            self.assertEqual(string_file.getvalue(), "FooBar")
        finally:
            consumer.unregisterProducer()

        yield consumer.wait()

        self.assertTrue(string_file.closed)
示例#4
0
    def test_pull_consumer(self):
        string_file = StringIO()
        consumer = BackgroundFileConsumer(string_file)

        try:
            producer = DummyPullProducer()

            yield producer.register_with_consumer(consumer)

            yield producer.write_and_wait("Foo")

            self.assertEqual(string_file.getvalue(), "Foo")

            yield producer.write_and_wait("Bar")

            self.assertEqual(string_file.getvalue(), "FooBar")
        finally:
            consumer.unregisterProducer()

        yield consumer.wait()

        self.assertTrue(string_file.closed)
示例#5
0
    def test_push_consumer(self):
        string_file = BlockingStringWrite()
        consumer = BackgroundFileConsumer(string_file, reactor=reactor)

        try:
            producer = NonCallableMock(spec_set=[])

            consumer.registerProducer(producer, True)

            consumer.write("Foo")
            yield string_file.wait_for_n_writes(1)

            self.assertEqual(string_file.buffer, "Foo")

            consumer.write("Bar")
            yield string_file.wait_for_n_writes(2)

            self.assertEqual(string_file.buffer, "FooBar")
        finally:
            consumer.unregisterProducer()

        yield consumer.wait()

        self.assertTrue(string_file.closed)
示例#6
0
    def test_push_consumer(self):
        string_file = BlockingStringWrite()
        consumer = BackgroundFileConsumer(string_file)

        try:
            producer = NonCallableMock(spec_set=[])

            consumer.registerProducer(producer, True)

            consumer.write("Foo")
            yield string_file.wait_for_n_writes(1)

            self.assertEqual(string_file.buffer, "Foo")

            consumer.write("Bar")
            yield string_file.wait_for_n_writes(2)

            self.assertEqual(string_file.buffer, "FooBar")
        finally:
            consumer.unregisterProducer()

        yield consumer.wait()

        self.assertTrue(string_file.closed)