Exemplo n.º 1
0
    def tests_just_for_coverage(self):
        request_id = "requestID"
        message_id = "messageID"
        reply_payload = {"reply": "payload"}
        reply_rpc = reply.ReplyRPC(None, "AGENTID", None, request_id,
                                   reply_payload, self.db)
        reply_doc = {
            "request_id": request_id,
            "message_id": message_id,
        }

        passed = False
        try:
            reply_rpc.incoming_message(reply_doc)
        except exceptions.MissingMessageParameterException:
            passed = True
        self.assertTrue(passed)

        passed = False
        reply_doc['type'] = 'nothing'
        try:
            reply_rpc.incoming_message(reply_doc)
        except exceptions.InvalidMessageParameterValueException:
            passed = True
        self.assertTrue(passed)

        reply_rpc._sm.mapping_to_digraph()
Exemplo n.º 2
0
    def test_reply_skip(self):
        conn = mock.Mock()
        reply_listener = mock.Mock()

        request_id = "requestID"
        message_id = "messageID"
        reply_payload = {"reply": "payload"}
        incoming_message = {"incoming": "info"}

        reply_rpc = reply.ReplyRPC(reply_listener, "AGENTID", conn, request_id,
                                   incoming_message, self.db)
        reply_rpc.reply(reply_payload)

        reply_doc = {
            "type": types.MessageTypes.ACK,
            "request_id": request_id,
            "message_id": message_id,
            "payload": reply_payload
        }
        reply_rpc.incoming_message(reply_doc)
        reply_listener.message_done.assert_called_once_with(reply_rpc)

        (param_list, keywords) = conn.send.call_args
        send_doc = param_list[0]
        self.assertTrue('message_id' in send_doc)
        self.assertTrue('request_id' in send_doc)
        self.assertTrue('type' in send_doc)
        self.assertEqual(send_doc['type'], types.MessageTypes.REPLY)
        self.assertEqual(send_doc['payload'], reply_payload)
        self.assertEqual(conn.send.call_count, 1)
Exemplo n.º 3
0
    def test_reply_ack_timeout(self):
        conn = mock.Mock()
        reply_listener = mock.Mock()

        request_id = "requestID"
        message_id = "messageID"
        reply_payload = {"reply": "payload"}
        incoming_message = {"incoming": "info"}

        reply_rpc = reply.ReplyRPC(reply_listener,
                                   "AGENTID",
                                   conn,
                                   request_id,
                                   incoming_message,
                                   self.db,
                                   timeout=1)
        reply_rpc.reply(reply_payload)

        reply_doc = {
            "type": types.MessageTypes.ACK,
            "request_id": request_id,
            "message_id": message_id,
            "payload": reply_payload
        }
        dcm_events.poll(timeblock=1.2)
        reply_rpc.incoming_message(reply_doc)
        reply_listener.message_done.assert_called_once_with(reply_rpc)
        self.assertEqual(conn.send.call_count, 2)
Exemplo n.º 4
0
    def test_request_retrans_after_reply(self):
        conn = mock.Mock()
        reply_listener = mock.Mock()

        request_id = "requestID"
        message_id = "messageID"
        reply_payload = {"reply": "payload"}

        reply_rpc = reply.ReplyRPC(reply_listener, "AGENTID", conn, request_id,
                                   reply_payload, self.db)
        request_retrans_doc = {
            'type': types.MessageTypes.REQUEST,
            'request_id': request_id,
            'message_id': message_id,
            'payload': reply_payload
        }
        reply_rpc.reply(reply_payload)
        reply_rpc.incoming_message(request_retrans_doc)

        self.assertEqual(conn.send.call_count, 2)

        reply_doc = {
            "type": types.MessageTypes.ACK,
            "request_id": request_id,
            "message_id": message_id,
        }
        reply_rpc.incoming_message(reply_doc)
Exemplo n.º 5
0
    def test_request_nack(self):
        conn = mock.Mock()
        reply_listener = mock.Mock()

        request_id = "requestID"
        reply_payload = {"reply": "payload"}

        reply_rpc = reply.ReplyRPC(reply_listener, "AGENTID", conn, request_id,
                                   reply_payload, self.db)
        reply_rpc.nak({})
Exemplo n.º 6
0
    def test_request_retrans_before_ack(self):
        conn = mock.Mock()
        reply_listener = mock.Mock()

        request_id = "requestID"
        message_id = "messageID"
        reply_payload = {"reply": "payload"}

        reply_rpc = reply.ReplyRPC(reply_listener, "AGENTID", conn, request_id,
                                   reply_payload, self.db)
        request_retrans_doc = {
            'type': types.MessageTypes.REQUEST,
            'request_id': request_id,
            'message_id': message_id,
            'payload': reply_payload
        }
        reply_rpc.incoming_message(request_retrans_doc)
        reply_rpc.ack(None, None, None)
Exemplo n.º 7
0
    def test_reply_ack_simple(self):

        conn = mock.Mock()
        reply_listener = mock.Mock()

        request_id = "requestID"
        message_id = "messageID"
        reply_payload = {"reply": "payload"}

        reply_rpc = reply.ReplyRPC(reply_listener, "AGENT_ID", conn,
                                   request_id, {"request_id": request_id},
                                   self.db)
        reply_rpc.ack(None, None, None)
        reply_rpc.reply(reply_payload)

        reply_doc = {
            "type": types.MessageTypes.ACK,
            "request_id": request_id,
            "message_id": message_id,
        }
        reply_rpc.incoming_message(reply_doc)
        reply_listener.message_done.assert_called_once_with(reply_rpc)

        self.assertEqual(conn.send.call_count, 2)

        (param_list, keywords) = conn.send.call_args_list[0]
        ack_doc = param_list[0]

        self.assertEqual(ack_doc["type"], types.MessageTypes.ACK)
        self.assertEqual(ack_doc["request_id"], request_id)

        (param_list, keywords) = conn.send.call_args_list[1]
        reply_doc = param_list[0]

        self.assertTrue('message_id' in reply_doc)

        self.assertTrue('request_id' in reply_doc)
        self.assertTrue('type' in reply_doc)
        self.assertEqual(reply_doc['type'], types.MessageTypes.REPLY)
        self.assertEqual(reply_doc['payload'], reply_payload)