Exemplo n.º 1
0
    def test_posting_a_message(self):
        """Given that I have an RMQ message producer
            when I send that message via the producer
            then I should be able to read that message via the consumer
        """
        test_topic = "kombu_gateway_tests" + str(uuid4())
        header = BrightsideMessageHeader(uuid4(), test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody("test content")
        message = BrightsideMessage(header, body)

        queue_name = "brightside_tests" + str(uuid4())
        consumer = ArameConsumer(
            self._connection,
            BrightsideConsumerConfiguration(self._pipeline, queue_name,
                                            test_topic))

        self._producer.send(message)

        read_message = consumer.receive(3)
        consumer.acknowledge(read_message)

        self.assertEqual(message.id, read_message.id)
        self.assertEqual(message.body.value, read_message.body.value)
        self.assertTrue(consumer.has_acknowledged(read_message))
Exemplo n.º 2
0
    def test_requeueing_a_message(self):
        """Given that I have an RMQ consumer
            when I requeue a message
            then it should return to the end of the queue
        """
        test_topic = "kombu_gateway_tests" + str(uuid4())
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody(
            JsonRequestSerializer(request=request).serialize_to_json(),
            BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        queue_name = "brightside_tests" + str(uuid4())
        consumer = ArameConsumer(
            self._connection,
            BrightsideConsumerConfiguration(self._pipeline, queue_name,
                                            test_topic))

        self._producer.send(message)

        read_message = consumer.receive(3)

        consumer.requeue(read_message)

        # should now be able to receive it again
        reread_message = consumer.receive(3)
        consumer.acknowledge(reread_message)

        self.assertEqual(message.id, reread_message.id)
        self.assertEqual(message.body.value, reread_message.body.value)
        self.assertTrue(consumer.has_acknowledged(reread_message))
Exemplo n.º 3
0
class ArameGatewayTests(unittest.TestCase):

    test_topic = "kombu_gateway_tests"

    def setUp(self):
        self._connection = ArameConnection("amqp://*****:*****@localhost:5672//", "paramore.brighter.exchange")
        self._producer = ArameProducer(self._connection)
        self._consumer = ArameConsumer(self._connection, "brightside_tests", self.test_topic)

    def test_posting_a_message(self):
        """Given that I have an RMQ message producer
            when I send that message via the producer
            then I should be able to read that message via the consumer
        """
        header = BrightsideMessageHeader(uuid4(), self.test_topic, BrightsideMessageType.command, uuid4())
        body = BrightsideMessageBody("test content")
        message = BrightsideMessage(header, body)

        self._consumer.purge()

        self._producer.send(message)

        read_message = self._consumer.receive(3)
        self._consumer.acknowledge(read_message)

        self.assertEqual(message.id, read_message.id)
        self.assertEqual(message.body.value, read_message.body.value)
        self.assertTrue(self._consumer.has_acknowledged(read_message))

    def test_posting_object_state(self):
        """Given that I have an RMQ producer
            when I deserialize an object via the producer
            then I should be able to re-hydrate it via the consumer
        """
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), self.test_topic, BrightsideMessageType.command, uuid4())
        body = BrightsideMessageBody(JsonRequestSerializer(request=request).serialize_to_json(), BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        self._consumer.purge()

        self._producer.send(message)

        read_message = self._consumer.receive(3)
        self._consumer.acknowledge(read_message)

        deserialized_request = JsonRequestSerializer(request=TestMessage(), serialized_request=read_message.body.value)\
            .deserialize_from_json()

        self.assertIsNotNone(deserialized_request)
        self.assertEqual(request.bool_value, deserialized_request.bool_value)
        self.assertEqual(request.float_value, deserialized_request.float_value)
        self.assertEqual(request.integer_value, deserialized_request.integer_value)
        self.assertEqual(request.id, deserialized_request.id)
Exemplo n.º 4
0
class ArameGatewayTests(unittest.TestCase):

    test_topic = "kombu_gateway_tests"

    def setUp(self):
        config = TestConfig()
        self._connection = Connection(config.broker_uri,
                                      "paramore.brightside.exchange",
                                      is_durable=True)
        self._producer = ArameProducer(self._connection)
        self._pipeline = Queue()
        self._consumer = ArameConsumer(
            self._connection,
            BrightsideConsumerConfiguration(self._pipeline, "brightside_tests",
                                            self.test_topic))

    def test_posting_a_message(self):
        """Given that I have an RMQ message producer
            when I send that message via the producer
            then I should be able to read that message via the consumer
        """
        header = BrightsideMessageHeader(uuid4(), self.test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody("test content")
        message = BrightsideMessage(header, body)

        self._consumer.purge()

        self._producer.send(
            message
        )  # if errors with akes 1 positional argument but 2 were given then manually purge

        read_message = self._consumer.receive(3)
        self._consumer.acknowledge(read_message)

        self.assertEqual(message.id, read_message.id)
        self.assertEqual(message.body.value, read_message.body.value)
        self.assertTrue(self._consumer.has_acknowledged(read_message))

    def test_requeueing_a_message(self):
        """Given that I have an RMQ consumer
            when I requeue a message
            then it should return to the end of the queue
        """
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), self.test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody(
            JsonRequestSerializer(request=request).serialize_to_json(),
            BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        self._consumer.purge(
        )  # if errors with akes 1 positional argument but 2 were given then manually purge

        self._producer.send(message)

        read_message = self._consumer.receive(3)

        self._consumer.requeue(read_message)

        # should now be able to receive it again
        reread_message = self._consumer.receive(3)
        self._consumer.acknowledge(reread_message)

        self.assertEqual(message.id, reread_message.id)
        self.assertEqual(message.body.value, reread_message.body.value)
        self.assertTrue(self._consumer.has_acknowledged(reread_message))

    def test_posting_object_state(self):
        """Given that I have an RMQ producer
            when I deserialize an object via the producer
            then I should be able to re-hydrate it via the consumer
        """
        request = TestMessage()
        header = BrightsideMessageHeader(uuid4(), self.test_topic,
                                         BrightsideMessageType.MT_COMMAND)
        body = BrightsideMessageBody(
            JsonRequestSerializer(request=request).serialize_to_json(),
            BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        self._consumer.purge(
        )  # if errors with akes 1 positional argument but 2 were given then manually purge

        self._producer.send(message)

        read_message = self._consumer.receive(3)
        self._consumer.acknowledge(read_message)

        deserialized_request = JsonRequestSerializer(request=TestMessage(), serialized_request=read_message.body.value)\
            .deserialize_from_json()

        self.assertIsNotNone(deserialized_request)
        self.assertEqual(request.bool_value, deserialized_request.bool_value)
        self.assertEqual(request.float_value, deserialized_request.float_value)
        self.assertEqual(request.integer_value,
                         deserialized_request.integer_value)
        self.assertEqual(request.id, deserialized_request.id)