Beispiel #1
0
def _GetMessageWithStruct(struct, ordinal, flags, request_id):
    header = messaging.MessageHeader(ordinal, flags,
                                     0 if request_id is None else request_id)
    data = header.Serialize()
    (payload, handles) = struct.Serialize()
    data.extend(payload)
    return messaging.Message(data, handles, header)
Beispiel #2
0
    def testRequestResponse(self):
        header_data = messaging.MessageHeader(
            0, messaging.MESSAGE_EXPECTS_RESPONSE_FLAG).Serialize()
        message = messaging.Message(header_data)
        back_messages = []

        def OnBackMessage(message):
            back_messages.append(message)
            return True

        self.router.AcceptWithResponder(
            message, messaging.ForwardingMessageReceiver(OnBackMessage))
        self.loop.RunUntilIdle()
        self.assertFalse(self.received_errors)
        self.assertFalse(self.received_messages)
        (res, data, _) = self.handle.ReadMessage(bytearray(len(header_data)))
        self.assertEquals(system.RESULT_OK, res)
        message_header = messaging.MessageHeader.Deserialize(data[0])
        self.assertNotEquals(message_header.request_id, 0)
        response_header_data = messaging.MessageHeader(
            0, messaging.MESSAGE_IS_RESPONSE_FLAG,
            message_header.request_id).Serialize()
        self.handle.WriteMessage(response_header_data)
        self.loop.RunUntilIdle()
        self.assertFalse(self.received_errors)
        self.assertEquals(len(back_messages), 1)
        self.assertEquals(back_messages[0].data, response_header_data)
Beispiel #3
0
 def runTest(self, prefix, message_receiver):
   for (filename, data, expected) in ValidationTest.GetData(prefix):
     self.assertEquals(len(data.error_message), 0)
     handles = [HandleMock() for _ in xrange(data.num_handles)]
     message = messaging.Message(data.data, handles)
     self.assertEquals(message_receiver.Accept(message), expected,
                       'Unexpected result for test: %s' % filename)
Beispiel #4
0
 def testSimpleMessage(self):
     header_data = messaging.MessageHeader(0, messaging.NO_FLAG).Serialize()
     message = messaging.Message(header_data)
     self.router.Accept(message)
     self.loop.RunUntilIdle()
     self.assertFalse(self.received_errors)
     self.assertFalse(self.received_messages)
     (res, data, _) = self.handle.ReadMessage(bytearray(len(header_data)))
     self.assertEquals(system.RESULT_OK, res)
     self.assertEquals(data[0], header_data)
Beispiel #5
0
def _GetMessage(method, flags, *args, **kwargs):
    if flags == messaging.MESSAGE_IS_RESPONSE_FLAG:
        struct = method.response_struct(*args, **kwargs)
    else:
        struct = method.parameters_struct(*args, **kwargs)
    header = messaging.MessageHeader(method.ordinal, flags)
    data = header.Serialize()
    (payload, handles) = struct.Serialize()
    data.extend(payload)
    return messaging.Message(data, handles, header)
Beispiel #6
0
 def testConnectorWrite(self):
     self.connector.Accept(messaging.Message())
     (result, _, _) = self.handle.ReadMessage()
     self.assertEquals(result, system.RESULT_OK)
     self.assertFalse(self.received_errors)