Ejemplo n.º 1
0
    def test_receive_connected(self):
        client = AsyncClient()
        frame = Frame(Command.CONNECTED,
                      {'version': '1.2', Headers.HEARTEBEAT: '8000,0'})

        client.handle_frame(None, frame)

        self.assertTrue(client.connected)
Ejemplo n.º 2
0
    def test_receive_connected(self):
        client = AsyncClient()
        frame = Frame(Command.CONNECTED,
                      {'version': '1.2', Headers.HEARTBEAT: '8000,0'})

        client.handle_frame(None, frame)

        self.assertTrue(client.connected)
Ejemplo n.º 3
0
    def test_manage_subscription(self):
        client = AsyncClient()

        subscription = client.subscribe(destination='jms.queue.events',
                                        ack='client',
                                        sub_id=str(uuid4()))
        client.unsubscribe(subscription)
        self.assertTrue(len(client._subscriptions) == 0)
Ejemplo n.º 4
0
    def test_manage_subscription(self):
        client = AsyncClient()

        subscription = client.subscribe(destination='jms.queue.events',
                                        ack='client',
                                        sub_id=str(uuid4()))
        client.unsubscribe(subscription)
        self.assertEqual(len(client._subscriptions), 0)
Ejemplo n.º 5
0
    def test_set_heartbeat(self):
        client = AsyncClient(incoming_heartbeat=200, outgoing_heartbeat=100)
        client.handle_connect()

        req_frame = client.pop_message()

        self.assertEqual(req_frame.command, Command.CONNECT)
        self.assertEqual(req_frame.headers[Headers.ACCEPT_VERSION], '1.2')
        self.assertEqual(req_frame.headers[Headers.HEARTBEAT], '100,200')
Ejemplo n.º 6
0
    def test_connect(self):
        client = AsyncClient()
        client.handle_connect()

        req_frame = client.pop_message()

        self.assertEqual(req_frame.command, Command.CONNECT)
        self.assertEqual(req_frame.headers[Headers.ACCEPT_VERSION], '1.2')
        self.assertEqual(req_frame.headers[Headers.HEARTEBEAT], '0,5000')
Ejemplo n.º 7
0
    def test_connect(self):
        client = AsyncClient()
        client.handle_connect()

        req_frame = client.pop_message()

        self.assertEquals(req_frame.command, Command.CONNECT)
        self.assertEquals(req_frame.headers[Headers.ACCEPT_VERSION], '1.2')
        self.assertEquals(req_frame.headers[Headers.HEARTEBEAT], '0,5000')
Ejemplo n.º 8
0
    def test_failed_send(self):
        client = AsyncClient()

        data = ('{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},'
                '"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}')
        headers = {Headers.REPLY_TO: 'jms.topic.vdsm_responses',
                   Headers.CONTENT_LENGTH: '103'}

        with self.assertRaises(StompError):
            with MonkeyPatchScope([(yajsonrpc, 'CALL_TIMEOUT',
                                    0.5)]):
                client.send('jms.topic.vdsm_requests', data, headers)
Ejemplo n.º 9
0
    def test_failed_send(self):
        client = AsyncClient()

        data = ('{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},'
                '"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}')
        headers = {Headers.REPLY_TO: 'jms.topic.vdsm_responses',
                   Headers.CONTENT_LENGTH: '103'}

        with self.assertRaises(StompError):
            with MonkeyPatchScope([(yajsonrpc, 'CALL_TIMEOUT',
                                    0.5)]):
                client.send('jms.topic.vdsm_requests', data, headers)
Ejemplo n.º 10
0
    def test_subscribe(self):
        client = AsyncClient()

        id = str(uuid4())
        client.subscribe(destination='jms.queue.events', ack='client',
                         sub_id=id)

        req_frame = client.pop_message()
        self.assertEqual(len(client._subscriptions), 1)
        self.assertEqual(req_frame.command, Command.SUBSCRIBE)
        self.assertEqual(req_frame.headers['destination'], 'jms.queue.events')
        self.assertEqual(req_frame.headers['id'], id)
        self.assertEqual(req_frame.headers['ack'], 'client')
Ejemplo n.º 11
0
    def test_subscribe(self):
        client = AsyncClient()

        id = str(uuid4())
        client.subscribe(destination='jms.queue.events', ack='client',
                         sub_id=id)

        req_frame = client.pop_message()
        self.assertEqual(len(client._subscriptions), 1)
        self.assertEqual(req_frame.command, Command.SUBSCRIBE)
        self.assertEqual(req_frame.headers['destination'], 'jms.queue.events')
        self.assertEqual(req_frame.headers['id'], id)
        self.assertEqual(req_frame.headers['ack'], 'client')
Ejemplo n.º 12
0
    def test_restore_subcsriptions(self):
        client = AsyncClient()
        client.subscribe(destination='jms.queue.events',
                         ack='client',
                         sub_id=str(uuid4()))
        client.subscribe(destination='jms.queue.events',
                         ack='client',
                         sub_id=str(uuid4()))
        client.subscribe(destination='jms.queue.events',
                         ack='client',
                         sub_id=str(uuid4()))

        client.restore_subscriptions()
        self.assertEqual(len(client._subscriptions), 3)
Ejemplo n.º 13
0
    def test_send(self):
        client = AsyncClient()
        data = ('{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},'
                '"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}')
        headers = {Headers.REPLY_TO: 'jms.topic.vdsm_responses',
                   Headers.CONTENT_LENGTH: '103'}
        client.send('jms.topic.vdsm_requests', data, headers)

        req_frame = client.pop_message()
        self.assertEquals(req_frame.command, Command.SEND)
        self.assertEquals(req_frame.headers['destination'],
                          'jms.topic.vdsm_requests')
        self.assertEquals(req_frame.headers[Headers.REPLY_TO],
                          'jms.topic.vdsm_responses')
        self.assertEquals(req_frame.body, data)
Ejemplo n.º 14
0
    def test_send(self):
        client = AsyncClient()
        data = ('{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},'
                '"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}')
        headers = {
            Headers.REPLY_TO: 'jms.topic.vdsm_responses',
            Headers.CONTENT_LENGTH: '103'
        }
        client.send('jms.topic.vdsm_requests', data, headers)

        req_frame = client.pop_message()
        self.assertEquals(req_frame.command, Command.SEND)
        self.assertEquals(req_frame.headers['destination'],
                          'jms.topic.vdsm_requests')
        self.assertEquals(req_frame.headers[Headers.REPLY_TO],
                          'jms.topic.vdsm_responses')
        self.assertEquals(req_frame.body, data)
Ejemplo n.º 15
0
    def test_resend(self):
        client = AsyncClient()

        data = (b'{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},'
                b'"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}')
        headers = {
            Headers.REPLY_TO: 'jms.topic.vdsm_responses',
            Headers.CONTENT_LENGTH: '103'
        }

        with MonkeyPatchScope([(yajsonrpc, 'CALL_TIMEOUT', 0.5)]):
            client.send('jms.topic.vdsm_requests', data, headers)
            client._connected.set()
            req_frame = client.pop_message()
            self.assertEqual(req_frame.command, Command.SEND)
            self.assertEqual(req_frame.headers['destination'],
                             'jms.topic.vdsm_requests')
            self.assertEqual(req_frame.headers[Headers.REPLY_TO],
                             'jms.topic.vdsm_responses')
            self.assertEqual(req_frame.body, data)
Ejemplo n.º 16
0
    def test_unsubscribe_with_different_id(self):
        client = AsyncClient()

        client.subscribe(destination='jms.queue.events',
                         ack='client-individual',
                         sub_id=str(uuid4()))
        # ignore subscribe frame
        client.pop_message()

        client.unsubscribe(
            TestSubscription('jms.queue.events', 'ad052acb-a934-4e10-8ec3'))

        self.assertTrue(len(client._subscriptions) == 1)
        self.assertFalse(client.has_outgoing_messages)
Ejemplo n.º 17
0
    def test_receive_message(self):
        client = AsyncClient()
        id = 'ad052acb-a934-4e10-8ec3-00c7417ef8d1'
        headers = {Headers.CONTENT_LENGTH: '78',
                   Headers.DESTINATION: 'jms.topic.vdsm_responses',
                   Headers.CONTENT_TYPE: 'application/json',
                   Headers.SUBSCRIPTION: id}
        body = ('{"jsonrpc": "2.0", "id": "e8a936a6-d886-4cfa-97b9-2d54209053f'
                'f", "result": []}')
        frame = Frame(command=Command.MESSAGE, headers=headers, body=body)

        def message_handler(sub, frame):
            client.queue_frame(frame)

        client.subscribe('', 'auto', id, message_handler)
        # ignore subscribe frame
        client.pop_message()

        client.handle_frame(None, frame)

        self.assertEqual(frame, client.pop_message())
Ejemplo n.º 18
0
    def test_unsubscribe_with_different_id(self):
        client = AsyncClient()

        client.subscribe(destination='jms.queue.events',
                         ack='client-individual',
                         sub_id=str(uuid4()))
        # ignore subscribe frame
        client.pop_message()

        client.unsubscribe(TestSubscription('jms.queue.events',
                                            'ad052acb-a934-4e10-8ec3'))

        self.assertEqual(len(client._subscriptions), 1)
        self.assertFalse(client.has_outgoing_messages)
Ejemplo n.º 19
0
    def test_receive_message(self):
        client = AsyncClient()
        id = 'ad052acb-a934-4e10-8ec3-00c7417ef8d1'
        headers = {Headers.CONTENT_LENGTH: '78',
                   Headers.DESTINATION: 'jms.topic.vdsm_responses',
                   Headers.CONTENT_TYPE: 'application/json',
                   Headers.SUBSCRIPTION: id}
        body = ('{"jsonrpc": "2.0", "id": "e8a936a6-d886-4cfa-97b9-2d54209053f'
                'f", "result": []}')
        frame = Frame(command=Command.MESSAGE, headers=headers, body=body)

        def message_handler(sub, frame):
            client.queue_frame(frame)

        client.subscribe('', 'auto', id, message_handler)
        # ignore subscribe frame
        client.pop_message()

        client.handle_frame(None, frame)

        self.assertEqual(frame, client.pop_message())
Ejemplo n.º 20
0
    def test_receive_error(self):
        client = AsyncClient()
        frame = Frame(command=Command.ERROR, body='Test error')

        with self.assertRaises(StompError):
            client.handle_frame(None, frame)
Ejemplo n.º 21
0
    def test_receive_error(self):
        client = AsyncClient()
        frame = Frame(command=Command.ERROR, body='Test error')

        with self.assertRaises(StompError):
            client.handle_frame(None, frame)