예제 #1
0
    def test_abort(self):
        consumer = RabbitQueue(global_session, next(queue_names))
        routing_key = RabbitRoutingKey(global_session, next(key_names))
        routing_key.associateConsumerNow(consumer)

        for data in range(90, 100):
            routing_key.send(data)

        # Messages sent using send() are forgotten on abort.
        transaction.abort()
        self.assertRaises(QueueEmpty, consumer.receive, timeout=2)
예제 #2
0
    def test_abort(self):
        consumer = RabbitQueue(global_session, next(queue_names))
        routing_key = RabbitRoutingKey(global_session, next(key_names))
        routing_key.associateConsumerNow(consumer)

        for data in range(90, 100):
            routing_key.send(data)

        # Messages sent using send() are forgotten on abort.
        transaction.abort()
        self.assertRaises(QueueEmpty, consumer.receive, timeout=2)
예제 #3
0
 def test_associateConsumerNow(self):
     # associateConsumerNow() associates the consumer right away.
     consumer = RabbitQueue(global_session, next(queue_names))
     routing_key = RabbitRoutingKey(global_session, next(key_names))
     routing_key.associateConsumerNow(consumer)
     routing_key.sendNow('now')
     routing_key.send('later')
     # There is already something in the queue.
     self.assertEqual('now', consumer.receive(timeout=2))
     transaction.commit()
     # Now that the transaction has been committed there is another item in
     # the queue.
     self.assertEqual('later', consumer.receive(timeout=2))
예제 #4
0
 def test_associateConsumerNow(self):
     # associateConsumerNow() associates the consumer right away.
     consumer = RabbitQueue(global_session, next(queue_names))
     routing_key = RabbitRoutingKey(global_session, next(key_names))
     routing_key.associateConsumerNow(consumer)
     routing_key.sendNow('now')
     routing_key.send('later')
     # There is already something in the queue.
     self.assertEqual('now', consumer.receive(timeout=2))
     transaction.commit()
     # Now that the transaction has been committed there is another item in
     # the queue.
     self.assertEqual('later', consumer.receive(timeout=2))
예제 #5
0
 def test_associateConsumer(self):
     # associateConsumer() only associates the consumer at transaction
     # commit time. However, order is preserved.
     consumer = RabbitQueue(global_session, next(queue_names))
     routing_key = RabbitRoutingKey(global_session, next(key_names))
     routing_key.associateConsumer(consumer)
     # The session is still not connected.
     self.assertFalse(global_session.is_connected)
     routing_key.sendNow('now')
     routing_key.send('later')
     # The queue is not found because the consumer has not yet been
     # associated with the routing key and the queue declared.
     self.assertRaises(QueueNotFound, consumer.receive, timeout=2)
     transaction.commit()
     # Now that the transaction has been committed, the consumer is
     # associated, and receives the deferred message.
     self.assertEqual('later', consumer.receive(timeout=2))
예제 #6
0
 def test_associateConsumer(self):
     # associateConsumer() only associates the consumer at transaction
     # commit time. However, order is preserved.
     consumer = RabbitQueue(global_session, next(queue_names))
     routing_key = RabbitRoutingKey(global_session, next(key_names))
     routing_key.associateConsumer(consumer)
     # The session is still not connected.
     self.assertFalse(global_session.is_connected)
     routing_key.sendNow('now')
     routing_key.send('later')
     # The queue is not found because the consumer has not yet been
     # associated with the routing key and the queue declared.
     self.assertRaises(QueueNotFound, consumer.receive, timeout=2)
     transaction.commit()
     # Now that the transaction has been committed, the consumer is
     # associated, and receives the deferred message.
     self.assertEqual('later', consumer.receive(timeout=2))
예제 #7
0
    def test_send(self):
        consumer = RabbitQueue(global_session, next(queue_names))
        routing_key = RabbitRoutingKey(global_session, next(key_names))
        routing_key.associateConsumerNow(consumer)

        for data in range(90, 100):
            routing_key.send(data)

        routing_key.sendNow('sync')
        # There is nothing in the queue except the sync we just sent.
        self.assertEqual('sync', consumer.receive(timeout=2))

        # Messages get sent on commit
        transaction.commit()
        for data in range(90, 100):
            self.assertEqual(data, consumer.receive())

        # There are no more messages. They have all been consumed.
        routing_key.sendNow('sync')
        self.assertEqual('sync', consumer.receive(timeout=2))
예제 #8
0
    def test_send(self):
        consumer = RabbitQueue(global_session, next(queue_names))
        routing_key = RabbitRoutingKey(global_session, next(key_names))
        routing_key.associateConsumerNow(consumer)

        for data in range(90, 100):
            routing_key.send(data)

        routing_key.sendNow('sync')
        # There is nothing in the queue except the sync we just sent.
        self.assertEqual('sync', consumer.receive(timeout=2))

        # Messages get sent on commit
        transaction.commit()
        for data in range(90, 100):
            self.assertEqual(data, consumer.receive())

        # There are no more messages. They have all been consumed.
        routing_key.sendNow('sync')
        self.assertEqual('sync', consumer.receive(timeout=2))