Ejemplo n.º 1
0
    def test_constructor(self, n='test_Consumer_constructor'):
        c = compat.Consumer(self.connection,
                            queue=n,
                            exchange=n,
                            routing_key='rkey')
        self.assertIsInstance(c.backend, Channel)
        q = c.queues[0]
        self.assertTrue(q.durable)
        self.assertTrue(q.exchange.durable)
        self.assertFalse(q.auto_delete)
        self.assertFalse(q.exchange.auto_delete)
        self.assertEqual(q.name, n)
        self.assertEqual(q.exchange.name, n)

        c2 = compat.Consumer(self.connection,
                             queue=n + '2',
                             exchange=n + '2',
                             routing_key='rkey',
                             durable=False,
                             auto_delete=True,
                             exclusive=True)
        q2 = c2.queues[0]
        self.assertFalse(q2.durable)
        self.assertFalse(q2.exchange.durable)
        self.assertTrue(q2.auto_delete)
        self.assertTrue(q2.exchange.auto_delete)
Ejemplo n.º 2
0
    def test_constructor(self, n='test_Consumer_constructor'):
        c = compat.Consumer(self.connection,
                            queue=n,
                            exchange=n,
                            routing_key='rkey')
        assert isinstance(c.backend, Channel)
        q = c.queues[0]
        assert q.durable
        assert q.exchange.durable
        assert not q.auto_delete
        assert not q.exchange.auto_delete
        assert q.name == n
        assert q.exchange.name == n

        c2 = compat.Consumer(self.connection,
                             queue=n + '2',
                             exchange=n + '2',
                             routing_key='rkey',
                             durable=False,
                             auto_delete=True,
                             exclusive=True)
        q2 = c2.queues[0]
        assert not q2.durable
        assert not q2.exchange.durable
        assert q2.auto_delete
        assert q2.exchange.auto_delete
Ejemplo n.º 3
0
    def test_constructor(self, prefix="0daf8h21"):
        dcon = {
            "%s.xyx" % prefix: {
                "exchange": "%s.xyx" % prefix,
                "routing_key": "xyx"
            },
            "%s.xyz" % prefix: {
                "exchange": "%s.xyz" % prefix,
                "routing_key": "xyz"
            }
        }
        consumers = [
            compat.Consumer(self.connection,
                            queue=prefix + str(i),
                            exchange=prefix + str(i)) for i in range(3)
        ]
        c = compat.ConsumerSet(self.connection, consumers=consumers)
        c2 = compat.ConsumerSet(self.connection, from_dict=dcon)

        self.assertEqual(len(c.queues), 3)
        self.assertEqual(len(c2.queues), 2)

        c.add_consumer(
            compat.Consumer(self.connection,
                            queue=prefix + "xaxxxa",
                            exchange=prefix + "xaxxxa"))
        self.assertEqual(len(c.queues), 4)
        for cq in c.queues:
            self.assertIs(cq.channel, c.channel)

        c2.add_consumer_from_dict({
            "%s.xxx" % prefix: {
                "exchange": "%s.xxx" % prefix,
                "routing_key": "xxx"
            }
        })
        self.assertEqual(len(c2.queues), 3)
        for c2q in c2.queues:
            self.assertIs(c2q.channel, c2.channel)

        c.discard_all()
        self.assertEqual(c.channel.called.count("queue_purge"), 4)
        c.consume()

        c.close()
        c2.close()
        self.assertIn("basic_cancel", c.channel)
        self.assertIn("close", c.channel)
        self.assertIn("close", c2.channel)
Ejemplo n.º 4
0
    def test_constructor(self, prefix='0daf8h21'):
        dcon = {
            '%s.xyx' % prefix: {
                'exchange': '%s.xyx' % prefix,
                'routing_key': 'xyx'
            },
            '%s.xyz' % prefix: {
                'exchange': '%s.xyz' % prefix,
                'routing_key': 'xyz'
            }
        }
        consumers = [
            compat.Consumer(self.connection,
                            queue=prefix + str(i),
                            exchange=prefix + str(i)) for i in range(3)
        ]
        c = compat.ConsumerSet(self.connection, consumers=consumers)
        c2 = compat.ConsumerSet(self.connection, from_dict=dcon)

        self.assertEqual(len(c.queues), 3)
        self.assertEqual(len(c2.queues), 2)

        c.add_consumer(
            compat.Consumer(self.connection,
                            queue=prefix + 'xaxxxa',
                            exchange=prefix + 'xaxxxa'))
        self.assertEqual(len(c.queues), 4)
        for cq in c.queues:
            self.assertIs(cq.channel, c.channel)

        c2.add_consumer_from_dict({
            '%s.xxx' % prefix: {
                'exchange': '%s.xxx' % prefix,
                'routing_key': 'xxx'
            }
        })
        self.assertEqual(len(c2.queues), 3)
        for c2q in c2.queues:
            self.assertIs(c2q.channel, c2.channel)

        c.discard_all()
        self.assertEqual(c.channel.called.count('queue_purge'), 4)
        c.consume()

        c.close()
        c2.close()
        self.assertIn('basic_cancel', c.channel)
        self.assertIn('close', c.channel)
        self.assertIn('close', c2.channel)
Ejemplo n.º 5
0
    def test_constructor(self, prefix='0daf8h21'):
        dcon = {
            '%s.xyx' % prefix: {
                'exchange': '%s.xyx' % prefix,
                'routing_key': 'xyx'
            },
            '%s.xyz' % prefix: {
                'exchange': '%s.xyz' % prefix,
                'routing_key': 'xyz'
            }
        }
        consumers = [
            compat.Consumer(self.connection,
                            queue=prefix + str(i),
                            exchange=prefix + str(i)) for i in range(3)
        ]
        c = compat.ConsumerSet(self.connection, consumers=consumers)
        c2 = compat.ConsumerSet(self.connection, from_dict=dcon)

        assert len(c.queues) == 3
        assert len(c2.queues) == 2

        c.add_consumer(
            compat.Consumer(self.connection,
                            queue=prefix + 'xaxxxa',
                            exchange=prefix + 'xaxxxa'))
        assert len(c.queues) == 4
        for cq in c.queues:
            assert cq.channel is c.channel

        c2.add_consumer_from_dict(
            '%s.xxx' % prefix,
            exchange='%s.xxx' % prefix,
            routing_key='xxx',
        )
        assert len(c2.queues) == 3
        for c2q in c2.queues:
            assert c2q.channel is c2.channel

        c.discard_all()
        assert c.channel.called.count('queue_purge') == 4
        c.consume()

        c.close()
        c2.close()
        assert 'basic_cancel' in c.channel
        assert 'close' in c.channel
        assert 'close' in c2.channel
Ejemplo n.º 6
0
 def test_discard_all(self, n="test_discard_all"):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key="rkey")
     c.discard_all()
     self.assertIn("queue_purge", c.backend)
Ejemplo n.º 7
0
 def test__enter__exit__(self, n='test__enter__exit__'):
     c = compat.Consumer(self.connection, queue=n, exchange=n,
                         routing_key='rkey')
     x = c.__enter__()
     assert x is c
     x.__exit__()
     assert c._closed
Ejemplo n.º 8
0
 def test_process_next(self, n="test_process_next"):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key="rkey")
     self.assertRaises(NotImplementedError, c.process_next)
     c.close()
Ejemplo n.º 9
0
 def test__enter__exit__(self, n='test__enter__exit__'):
     c = compat.Consumer(self.connection, queue=n, exchange=n,
                         routing_key='rkey')
     x = c.__enter__()
     self.assertIs(x, c)
     x.__exit__()
     self.assertTrue(c._closed)
Ejemplo n.º 10
0
    def test_revive(self, n='test_revive'):
        c = compat.Consumer(self.connection, queue=n, exchange=n)
        cs = compat.ConsumerSet(self.connection, consumers=[c])

        with self.connection.channel() as c2:
            cs.revive(c2)
            self.assertIs(cs.backend, c2)
Ejemplo n.º 11
0
 def test_discard_all(self, n='test_discard_all'):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key='rkey')
     c.discard_all()
     self.assertIn('queue_purge', c.backend)
Ejemplo n.º 12
0
 def test__enter__exit__(self, n="test__enter__exit__"):
     c = compat.Consumer(self.connection, queue=n, exchange=n,
                         routing_key="rkey")
     x = c.__enter__()
     self.assertIs(x, c)
     x.__exit__()
     self.assertIn("close", c.backend)
     self.assertTrue(c._closed)
Ejemplo n.º 13
0
 def test_discard_all_filterfunc_not_supported(self, n='xjf21j21'):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key='rkey')
     with self.assertRaises(NotImplementedError):
         c.discard_all(filterfunc=lambda x: x)
     c.close()
Ejemplo n.º 14
0
 def test_process_next(self, n='test_process_next'):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key='rkey')
     with self.assertRaises(NotImplementedError):
         c.process_next()
     c.close()
Ejemplo n.º 15
0
    def test_fetch(self, n="test_fetch"):
        c = compat.Consumer(self.connection, queue=n, exchange=n,
                            routing_key="rkey")
        self.assertIsNone(c.fetch())
        self.assertIsNone(c.fetch(no_ack=True))
        self.assertIn("basic_get", c.backend)

        callback_called = [False]

        def receive(payload, message):
            callback_called[0] = True

        c.backend.to_deliver.append("42")
        self.assertEqual(c.fetch().payload, "42")
        c.backend.to_deliver.append("46")
        c.register_callback(receive)
        self.assertEqual(c.fetch(enable_callbacks=True).payload, "46")
        self.assertTrue(callback_called[0])
Ejemplo n.º 16
0
    def test_fetch(self, n='test_fetch'):
        c = compat.Consumer(self.connection, queue=n, exchange=n,
                            routing_key='rkey')
        assert c.fetch() is None
        assert c.fetch(no_ack=True) is None
        assert 'basic_get' in c.backend

        callback_called = [False]

        def receive(payload, message):
            callback_called[0] = True

        c.backend.to_deliver.append('42')
        payload = c.fetch().payload
        assert payload == '42'
        c.backend.to_deliver.append('46')
        c.register_callback(receive)
        assert c.fetch(enable_callbacks=True).payload == '46'
        assert callback_called[0]
Ejemplo n.º 17
0
    def test_fetch(self, n='test_fetch'):
        c = compat.Consumer(self.connection, queue=n, exchange=n,
                            routing_key='rkey')
        self.assertIsNone(c.fetch())
        self.assertIsNone(c.fetch(no_ack=True))
        self.assertIn('basic_get', c.backend)

        callback_called = [False]

        def receive(payload, message):
            callback_called[0] = True

        c.backend.to_deliver.append('42')
        payload = c.fetch().payload
        self.assertEqual(payload, '42')
        c.backend.to_deliver.append('46')
        c.register_callback(receive)
        self.assertEqual(c.fetch(enable_callbacks=True).payload, '46')
        self.assertTrue(callback_called[0])
Ejemplo n.º 18
0
 def test_iterconsume(self, _iterconsume, n='test_iterconsume'):
     c = compat.Consumer(self.connection, queue=n, exchange=n)
     cs = compat.ConsumerSet(self.connection, consumers=[c])
     cs.iterconsume(limit=10, no_ack=True)
     _iterconsume.assert_called_with(c.connection, cs, True, 10)
Ejemplo n.º 19
0
 def test_iterconsume(self, n='test_iterconsume'):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key='rkey')
     c.close()
Ejemplo n.º 20
0
    def test__iter__(self, n='test__iter__'):
        c = compat.Consumer(self.connection, queue=n, exchange=n)
        c.iterqueue = Mock()

        c.__iter__()
        c.iterqueue.assert_called_with(infinite=True)
Ejemplo n.º 21
0
 def test_iterconsume_calls__iterconsume(self, it, n='test_iterconsume'):
     c = compat.Consumer(self.connection, queue=n, exchange=n)
     c.iterconsume(limit=10, no_ack=True)
     it.assert_called_with(c.connection, c, True, 10)
Ejemplo n.º 22
0
    def test_revive(self, n="test_revive"):
        c = compat.Consumer(self.connection, queue=n, exchange=n)

        with self.connection.channel() as c2:
            c.revive(c2)
            self.assertIs(c.backend, c2)
Ejemplo n.º 23
0
    def test_revive(self, n='test_revive'):
        c = compat.Consumer(self.connection, queue=n, exchange=n)

        with self.connection.channel() as c2:
            c.revive(c2)
            assert c.backend is c2
Ejemplo n.º 24
0
 def test_iterconsume(self, n="test_iterconsume"):
     c = compat.Consumer(self.connection,
                         queue=n,
                         exchange=n,
                         routing_key="rkey")
     c.close()