示例#1
0
    async def test_can_process_empty_message(self):
        stomp = StompReader(None, self.loop)
        stomp._protocol = Mock()

        stomp.data_received(None)

        await asyncio.sleep(0.001)
        stomp._protocol.feed_data.assert_not_called()
示例#2
0
    async def test_can_process_connected_frame(self, connect_handle_mock):
        stomp = StompReader(None, self.loop)

        stomp.data_received(b"CONNECTED\n"
                            b"heart-beat:1000,1000\n\n"
                            b"{}\x00")

        await asyncio.sleep(0.001)
        connect_handle_mock.assert_called_once()
示例#3
0
    async def test_can_process_exception(self, exception_handle_mock):
        stomp = StompReader(None, self.loop)

        stomp.data_received(b"SOMETHING\n"
                            b"message:Invalid error, blah, blah, blah\n"
                            b"\n"
                            b"Detail Error: blah, blah, blah\x00")

        await asyncio.sleep(0.001)
        exception_handle_mock.assert_called_once()
示例#4
0
    async def test_can_process_error(self, error_handle_mock):
        stomp = StompReader(None, self.loop)

        stomp.data_received(b'ERROR\n'
                            b'message:Invalid error, blah, blah, blah\n'
                            b'\n'
                            b'Detail Error: blah, blah, blah\x00')

        await asyncio.sleep(0.001)
        error_handle_mock.assert_called_once()
示例#5
0
    async def test_can_process_messages(self, message_handle_mock):
        stomp = StompReader(None, self.loop)

        await asyncio.sleep(0.001)

        stomp.data_received(
            b"MESSAGE\n"
            b"subscription:1\n"
            b"message-id:007\n"
            b"destination:/topic/test\n"
            b"\n"
            b"blahh-line-a\n\nblahh-line-b\n\nblahh-line-c\x00")

        await asyncio.sleep(0.001)
        message_handle_mock.assert_called_once()
示例#6
0
    async def test_can_process_long_messages(self, message_handle_mock):
        stomp = StompReader(None, self.loop)

        await asyncio.sleep(0.001)

        data = (
            b"MESSAGE\n"
            b"content-length:14\nexpires:0\ndestination:/topic/"
            b"xxxxxxxxxxxxxxxxxxxxxxxxxl"
            b"\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id"
            b":ID\\cxxxxxx-35207-1543430467768-204"
            b"\\c363\\c-1\\c1\\c463859\npersistent:true\ntimestamp"
            b":1548945234003\n\n222.222.22.222"
            b"\x00\nMESSAGE\ncontent-length:12\nexpires:0\ndestination:"
            b"/topic/xxxxxxxxxxxxxxxxxxxxxxxxxx"
            b"\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id"
            b":ID\\cxxxxxx-35207-1543430467768-204"
            b"\\c363\\c-1\\c1\\c463860\npersistent:true\ntimestamp"
            b":1548945234005\n\n88.88.888.88"
            b"\x00\nMESSAGE\ncontent-length:11\nexpires:0\ndestination:"
            b"/topic/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            b"\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id"
            b":ID\\cxxxxxx-35207-1543430467768-204"
            b"\\c362\\c-1\\c1\\c290793\npersistent:true\ntimestamp"
            b":1548945234005\n\n111.11.1.11"
            b"\x00\nMESSAGE\ncontent-length:14\nexpires:0\ndestination:"
            b"/topic/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            b"\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id"
            b":ID\\cxxxxxx-35207-1543430467768-204"
            b"\\c362\\c-1\\c1\\c290794\npersistent:true\ntimestamp:"
            b"1548945234005\n\n222.222.22.222"
            b"\x00\nMESSAGE\ncontent-length:12\nexpires:0\ndestination:"
            b"/topic/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            b"\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id"
            b":ID\\cxxxxxx-35207-1543430467768-204"
            b"\\c362\\c-1\\c1\\c290795\npersistent:true\ntimestamp:"
            b"1548945234005\n\n88.88.888.88\x00\nMESS")

        stomp.data_received(data)
        await asyncio.sleep(0.001)

        self.assertEqual(message_handle_mock.call_count, 5)
        self.assertEqual(bytes(stomp._protocol.current_command), b"MESS")
示例#7
0
    async def test_consecutive_calls_data_received(self, message_handle_mock):
        stomp = StompReader(None, self.loop)

        await asyncio.sleep(0.001)

        stomp.data_received(
            b"MESSAGE\n"
            b"subscription:1\n"
            b"message-id:007\n"
            b"destination:/topic/test\n"
            b"\n"
            b"blahh-line-a\n\nblahh-line-b\n\nblahh-line-c\x00")

        stomp.data_received(
            b"MESSAGE\n"
            b"subscription:1\n"
            b"message-id:007\n"
            b"destination:/topic/test\n"
            b"\n"
            b"blahh-line-a\n\nblahh-line-b\n\nblahh-line-c\x00")

        await asyncio.sleep(0.001)
        self.assertEqual(message_handle_mock.call_count, 2)
示例#8
0
    async def test_can_process_long_partial_messages(self,
                                                     message_handle_mock):
        stomp = StompReader(None, self.loop)

        await asyncio.sleep(0.001)

        stomp.data_received(
            b'MESSAGE\n'
            b'content-length:14\nexpires:0\ndestination:/topic/'
            b'xxxxxxxxxxxxxxxxxxxxxxxxxl'
            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id')
        await asyncio.sleep(0.001)

        stomp.data_received(
            b':ID\\cxxxxxx-35207-1543430467768-204'
            b'\\c363\\c-1\\c1\\c463859\npersistent:true\ntimestamp'
            b':1548945234003\n\n222.222.22.222'
            b'\x00\nMESSAGE\ncontent-length:12\nexpires:0\ndestination:'
            b'/topic/xxxxxxxxxxxxxxxxxxxxxxxxxx'
            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id'
            b':ID\\cxxxxxx-35207-1543430467768-204'
            b'\\c363\\c-1\\c1\\c463860\npersistent:true\ntimestamp'
            b':1548945234005\n\n88.88.888.88'
            b'\x00\nMESS')
        await asyncio.sleep(0.001)

        stomp.data_received(
            b'AGE\n'
            b'content-length:14\nexpires:0\ndestination:/topic/'
            b'xxxxxxxxxxxxxxxxxxxxxxxxxl'
            b'\nsubscription:1\npriority:4\nActiveMQ.MQTT.QoS:1\nmessage-id')
        await asyncio.sleep(0.001)

        stomp.data_received(
            b':ID\\cxxxxxx-35207-1543430467768-204'
            b'\\c363\\c-1\\c1\\c463859\npersistent:true\ntimestamp'
            b':1548945234003\n\n222.222.22.222'
            b'\x00')
        await asyncio.sleep(0.001)

        self.assertEqual(message_handle_mock.call_count, 3)
        self.assertEqual(b''.join(stomp._protocol.current_command), b'')
示例#9
0
    async def test_can_process_heartbeat(self):
        stomp = StompReader(None, self.loop)
        stomp.data_received(b"\n")

        await asyncio.sleep(0.001)