def add_response(context_response, invocation_result_response): if 'messages' in context_response: outgoing_messages = invocation_result_response.outgoing_messages for typename, id, message in context_response['messages']: outgoing = outgoing_messages.add() namespace, type = parse_typename(typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = id outgoing.argument.CopyFrom(message) if 'delayed_messages' in context_response: delayed_invocations = invocation_result_response.delayed_invocations for delay, typename, id, message in context_response[ 'delayed_messages']: outgoing = delayed_invocations.add() namespace, type, parse_typename(typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = id outgoing.delay_in_ms = delay outgoing.argument.CopyFrom(message) if 'egress_messages' in context_response: outgoing_egresses = invocation_result_response.outgoing_egresses for typename, message in context_response['egress_messages']: outgoing = outgoing_egresses.add() namespace, type = parse_typename(typename) outgoing.egress_namespace = namespace outgoing.egress_type = type outgoing.argument.CopyFrom(message)
def add_egress(context, invocation_result): outgoing_egresses = invocation_result.outgoing_egresses for typename, message in context.egresses: outgoing = outgoing_egresses.add() namespace, type = parse_typename(typename) outgoing.egress_namespace = namespace outgoing.egress_type = type outgoing.argument.CopyFrom(message)
def collect_egress(egresses: typing.List[EgressMessage], invocation_result): outgoing_egresses = invocation_result.outgoing_egresses for message in egresses: outgoing = outgoing_egresses.add() namespace, type = parse_typename(message.typename) outgoing.egress_namespace = namespace outgoing.egress_type = type outgoing.argument.CopyFrom(message.typed_value)
def add_outgoing_messages(context, invocation_result): outgoing_messages = invocation_result.outgoing_messages for typename, id, message in context.messages: outgoing = outgoing_messages.add() namespace, type = parse_typename(typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = id outgoing.argument.CopyFrom(message)
def collect_messages(messages: typing.List[Message], pb_invocation_result): pb_outgoing_messages = pb_invocation_result.outgoing_messages for message in messages: outgoing = pb_outgoing_messages.add() namespace, type = parse_typename(message.target_typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = message.target_id outgoing.argument.CopyFrom(message.typed_value)
def add_atomic_invocations(context, invocation_result): atomic_invocations = invocation_result.atomic_invocations for typename, id, message in context.atomic_invocations: outgoing = atomic_invocations.add() namespace, type = parse_typename(typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = id outgoing.argument.CopyFrom(message)
def add_delayed_messages(context, invocation_result): delayed_invocations = invocation_result.delayed_invocations for delay, typename, id, message in context.delayed_messages: outgoing = delayed_invocations.add() namespace, type = parse_typename(typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = id outgoing.delay_in_ms = delay outgoing.argument.CopyFrom(message)
def collect_delayed(delayed_messages: typing.List[typing.Tuple[timedelta, Message]], invocation_result): delayed_invocations = invocation_result.delayed_invocations for delay, message in delayed_messages: outgoing = delayed_invocations.add() namespace, type = parse_typename(message.target_typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = message.target_id outgoing.delay_in_ms = delay outgoing.argument.CopyFrom(message.typed_value)
def add_invocation_pairs(context, invocation_result): invocation_pairs = invocation_result.invocation_pairs for typename, id, message, compensating_message in context.invocation_pairs: invocation_pair = invocation_pairs.add() # Create initial namespace, type = parse_typename(typename) invocation_pair.initial_message.target.namespace = namespace invocation_pair.initial_message.target.type = type invocation_pair.initial_message.target.id = id invocation_pair.initial_message.argument.CopyFrom(message) # Create compensating invocation_pair.compensating_message.target.namespace = namespace invocation_pair.compensating_message.target.type = type invocation_pair.compensating_message.target.id = id invocation_pair.compensating_message.argument.CopyFrom( compensating_message)
def collect_delayed(delayed_messages: typing.List[DelayedMessage], invocation_result): delayed_invocations = invocation_result.delayed_invocations for delayed_message in delayed_messages: outgoing = delayed_invocations.add() if delayed_message.is_cancellation: # handle cancellation outgoing.cancellation_token = delayed_message.cancellation_token outgoing.is_cancellation_request = True else: message = delayed_message.message namespace, type = parse_typename(message.target_typename) outgoing.target.namespace = namespace outgoing.target.type = type outgoing.target.id = message.target_id outgoing.delay_in_ms = delayed_message.duration outgoing.argument.CopyFrom(message.typed_value) if delayed_message.cancellation_token is not None: outgoing.cancellation_token = delayed_message.cancellation_token
def test_empty_string(self): with self.assertRaises(ValueError): parse_typename("")
def test_no_namespace_and_name(self): with self.assertRaises(ValueError): parse_typename("/")
def test_example(self): namespace, name = parse_typename("foo/bar") self.assertEqual(namespace, "foo") self.assertEqual(name, "bar")