Exemplo n.º 1
0
    def test_requeue(self):
        messages = [
            self.message_factory(ids=[]),
            self.message_factory(ids=[]),
            self.message_factory(ids=[0]),
            self.message_factory(ids=[1, 2]),
            self.message_factory(ids=[3, 4, 5]),
            self.message_factory(ids=[6, 7, 8, 9]),
        ]

        flattener = indexing.MessageFlattener(messages)
        assert list(flattener.pending) == []

        lengths = [3, 3, 4, 4, 4, 5, 5, 5, 5, 6]

        # Forces the initial buffer load.
        # Will always be called in a for loop.
        iter(flattener)

        for i in range(10):
            assert i == next(flattener)
            flattener.requeue_pending()
            assert list(flattener.acked) == []
            assert list(flattener.pending) == []
            assert flattener.requeued == messages[:lengths[i]]

        for message in messages:
            assert message.message.requeue.called
Exemplo n.º 2
0
    def test_list(self):
        assert list(indexing.MessageFlattener([])) == []

        assert list(
            indexing.MessageFlattener([
                self.message_factory(ids=[1, 2, 3]),
            ])) == [1, 2, 3]

        assert list(
            indexing.MessageFlattener([
                self.message_factory(ids=[1, 2, 3]),
                self.message_factory(ids=[4]),
                self.message_factory(ids=[]),
                self.message_factory(ids=[]),
                self.message_factory(ids=[]),
                self.message_factory(ids=[5, 6]),
            ])) == [1, 2, 3, 4, 5, 6]
Exemplo n.º 3
0
    def test_moves_to_pending(self):
        messages = [
            self.message_factory(ids=[]),
            self.message_factory(ids=[]),
            self.message_factory(ids=[0]),
            self.message_factory(ids=[1, 2]),
            self.message_factory(ids=[3, 4, 5]),
            self.message_factory(ids=[6, 7, 8, 9]),
        ]

        flattener = indexing.MessageFlattener(messages)
        assert list(flattener.pending) == []

        lengths = [3, 3, 4, 4, 4, 5, 5, 5, 5, 6]

        # Forces the initial buffer load.
        # Will always be called in a for loop.
        iter(flattener)

        for i in range(10):
            assert i == next(flattener)
            assert list(flattener.pending) == messages[:lengths[i]]
Exemplo n.º 4
0
 def test_len(self, number):
     assert len(
         indexing.MessageFlattener(
             [self.message_factory() for _ in range(number)])) == number * 3