Beispiel #1
0
    def test_send_priorities(self):
        messages_to_send = []
        for i in range(0, 30):
            messages_to_send.append(
                create_message(b'LOW', priority=Priority.low))
            messages_to_send.append(
                create_message(b'NORMAL', priority=Priority.normal))
            messages_to_send.append(
                create_message(b'HIGH', priority=Priority.high))

        # Send messages with priority in random order
        shuffle(messages_to_send)
        self.send_messages(messages_to_send)

        # Should be received in order
        self.expected_messages = sorted(messages_to_send,
                                        reverse=True,
                                        key=lambda message: message.priority)

        # Give Qpid a bit of time for ordering if needed
        sleep(3)
        self.receive_messages()

        # Don't check identity, because only the priority order is preserved
        self.check_messages(check_identity=False)
Beispiel #2
0
    def test_failover_receive(self):
        expected_messages = (create_message(b'FOOBAR'),
                             create_message(b'FOOBAR'),
                             create_message(b'FOOBAR'))
        self.sender.queue(expected_messages)
        self.sender.send()

        self.receiver.limit = 3
        self.receiver.receive(timeout=timedelta(seconds=2))
        for received, expected in zip(self.received_messages,
                                      expected_messages):
            self.assertEqual(received.id, expected.id)
            self.assertEqual(received.body, expected.body)
Beispiel #3
0
    def test_receive_limit(self):
        self.send_messages(
            (create_message(b'FOOBAR1'), create_message(b'FOOBAR2'),
             create_message(b'FOOBAR3')))

        # Should first receive only 2
        self.receiver.limit = 2
        self.receive_messages()
        self.check_messages(expected_messages=self.expected_messages[:-1])

        # Receive the rest
        self.receiver.limit = None
        self.receive_messages()
        self.check_messages()
Beispiel #4
0
 def test_addressless_routable(self):
     message = create_message(b'FOOBAR')
     message.address = self.sender.address
     self.sender.address = None
     self.send_messages((message, ))
     self.receive_messages()
     self.check_messages()
Beispiel #5
0
    def setUp(self):
        self.properties = {'foo': 'bar'}
        self.origin_message = create_message(b'foobar', self.properties,
                                             Priority.high)
        self.origin_message.reply_to = 'foobar_address'
        self.origin_message.correlation_id = uuid4()

        self.reply_message = create_reply(self.origin_message, b'foobar-reply')
Beispiel #6
0
def send_messages():
    sender = Sender(server_url=SERVER_URL)
    messages = []
    for num in reversed(range(3)):
        message = create_message(f'Test message {num+1}')
        message.address = QUEUE_NAME
        messages.append(message)
    sender.queue(messages)
    sender.send()
Beispiel #7
0
    def test_multi_receive(self):
        expected_messages = [
            create_message(b'FOOBAR1'),
            create_message(b'FOOBAR2'),
            create_message(b'FOOBAR3')
        ]
        self.send_messages(expected_messages[0:-1])

        second_queue_address = uuid4().hex
        create_queue(second_queue_address,
                     durable=False,
                     auto_delete=True,
                     extra_properties={'qpid.auto_delete_timeout': 10})
        self.receiver.add_address(second_queue_address)

        second_sender = Sender(second_queue_address)
        second_sender.queue(expected_messages[-1:])
        second_sender.send()

        self.receive_messages()
        self.assertEqual(len(self.received_messages), len(expected_messages))
Beispiel #8
0
def main():
    try_create_queue(QUEUE_NAME)

    remote_service = RemoveService()
    remote_service.start()

    message = create_message(f'Test RPC message')

    rpc = RemoteProcedure(rpc_callback, QUEUE_NAME, SERVER_URL)
    rpc.call(message, TIMEOUT)

    sleep(3)
    remote_service.receiver.stop()
Beispiel #9
0
def message_send(args):
    properties = None
    if args.properties_file:
        try:
            properties = json.load(args.properties_file)
        except json.JSONDecodeError:
            print("Invalid JSON properties file\n")
            args.parser.print_help()
            exit(EX_DATAERR)

    message = create_message(args.message.encode(), properties)
    sender = Sender(args.address, args.broker_url)
    sender.queue(repeat(message, args.repeat))
    sender.send()
Beispiel #10
0
 def test_receive(self):
     self.send_messages(
         (create_message(b'FOOBAR1'), create_message(b'FOOBAR2'),
          create_message(b'FOOBAR3')))
     self.receive_messages()
     self.check_messages()
Beispiel #11
0
 def test_connection_error(self):
     rpc = RemoteProcedure(lambda m: True,
                           uuid4().hex,
                           server_url='amqp://*****:*****@example')
     with self.assertRaises(ConnectionError):
         rpc.call(create_message(b'FOOBAR'))
Beispiel #12
0
 def test_unroutable(self):
     with self.assertRaises(UnroutableMessage):
         create_reply(create_message(b'foobar'), b'foobar')
Beispiel #13
0
 def test_connection_error(self):
     sender = Sender(uuid4().hex,
                     server_url='amqp://*****:*****@example')
     sender.queue((create_message(b'FOOBAR'), ))
     with self.assertRaises(ConnectionError):
         sender.send()
Beispiel #14
0
 def setUp(self):
     self.properties = {'foo': 'bar'}
     self.message = create_message(b'foobar', self.properties)
Beispiel #15
0
 def test_content_type_none_native_dict(self):
     message = create_message({'foo': 'bar'})
     self.assertEqual(message.content_type, symbol('None'))
Beispiel #16
0
 def test_content_type_none_native_list(self):
     message = create_message([1, 2, 3])
     self.assertEqual(message.content_type, symbol('None'))
Beispiel #17
0
 def test_addressless_unroutable(self):
     with self.assertRaises(UnroutableMessage):
         sender = Sender()
         message = create_message(b'FOOBAR')
         sender.queue((message, ))
Beispiel #18
0
 def test_send_properties(self):
     message = create_message(b'FOOBAR', {'foo': 'bar', 'baz': 123})
     self.send_messages((message, ))
     self.receive_messages()
     self.check_messages()