Пример #1
0
 def setUp(self):
     self._invocation_link, self._service_link = self.create_transmitting_links(
     )
     self._invocation_mate = test_utilities.RecordingLink()
     self._service_mate = test_utilities.RecordingLink()
     self._invocation_link.join_link(self._invocation_mate)
     self._service_link.join_link(self._service_mate)
    def _test_lonely_invocation_with_termination(self, termination):
        test_operation_id = object()
        test_group = 'test package.Test Service'
        test_method = 'test method'
        invocation_link_mate = test_utilities.RecordingLink()

        channel = _intermediary_low.Channel('nonexistent:54321', None)
        invocation_link = invocation.invocation_link(
            channel, 'nonexistent',
            {(test_group, test_method): _NULL_BEHAVIOR},
            {(test_group, test_method): _NULL_BEHAVIOR})
        invocation_link.join_link(invocation_link_mate)
        invocation_link.start()

        ticket = links.Ticket(test_operation_id, 0, test_group, test_method,
                              links.Ticket.Subscription.FULL,
                              test_constants.SHORT_TIMEOUT, 1, None, None,
                              None, None, None, termination)
        invocation_link.accept_ticket(ticket)
        invocation_link_mate.block_until_tickets_satisfy(test_cases.terminated)

        invocation_link.stop()

        self.assertIsNot(invocation_link_mate.tickets()[-1].termination,
                         links.Ticket.Termination.COMPLETION)
Пример #3
0
  def testZeroMessageRoundTrip(self):
    test_operation_id = object()
    test_group = 'test package.Test Group'
    test_method = 'test method'
    identity_transformation = {(test_group, test_method): _IDENTITY}
    test_code = beta_interfaces.StatusCode.OK
    test_message = 'a test message'

    service_link = service.service_link(
        identity_transformation, identity_transformation)
    service_mate = test_utilities.RecordingLink()
    service_link.join_link(service_mate)
    port = service_link.add_port('[::]:0', None)
    service_link.start()
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_link = invocation.invocation_link(
        channel, None, None, identity_transformation, identity_transformation)
    invocation_mate = test_utilities.RecordingLink()
    invocation_link.join_link(invocation_mate)
    invocation_link.start()

    invocation_ticket = links.Ticket(
        test_operation_id, 0, test_group, test_method,
        links.Ticket.Subscription.FULL, test_constants.LONG_TIMEOUT, None, None,
        None, None, None, None, links.Ticket.Termination.COMPLETION, None)
    invocation_link.accept_ticket(invocation_ticket)
    service_mate.block_until_tickets_satisfy(test_cases.terminated)

    service_ticket = links.Ticket(
        service_mate.tickets()[-1].operation_id, 0, None, None, None, None,
        None, None, None, None, test_code, test_message,
        links.Ticket.Termination.COMPLETION, None)
    service_link.accept_ticket(service_ticket)
    invocation_mate.block_until_tickets_satisfy(test_cases.terminated)

    invocation_link.stop()
    service_link.begin_stop()
    service_link.end_stop()

    self.assertIs(
        service_mate.tickets()[-1].termination,
        links.Ticket.Termination.COMPLETION)
    self.assertIs(
        invocation_mate.tickets()[-1].termination,
        links.Ticket.Termination.COMPLETION)
    self.assertIs(invocation_mate.tickets()[-1].code, test_code)
    self.assertEqual(invocation_mate.tickets()[-1].message, test_message)
Пример #4
0
    def _perform_scenario_test(self, scenario):
        test_operation_id = object()
        test_group, test_method = scenario.group_and_method()
        test_code = _intermediary_low.Code.OK
        test_message = 'a scenario test message'

        service_link = service.service_link(
            {(test_group, test_method): scenario.deserialize_request},
            {(test_group, test_method): scenario.serialize_response})
        service_mate = test_utilities.RecordingLink()
        service_link.join_link(service_mate)
        port = service_link.add_port('[::]:0', None)
        service_link.start()
        channel = _intermediary_low.Channel('localhost:%d' % port, None)
        invocation_link = invocation.invocation_link(
            channel, 'localhost', None,
            {(test_group, test_method): scenario.serialize_request},
            {(test_group, test_method): scenario.deserialize_response})
        invocation_mate = test_utilities.RecordingLink()
        invocation_link.join_link(invocation_mate)
        invocation_link.start()

        invocation_ticket = links.Ticket(test_operation_id, 0, test_group,
                                         test_method,
                                         links.Ticket.Subscription.FULL,
                                         test_constants.LONG_TIMEOUT, None,
                                         None, None, None, None, None, None,
                                         None)
        invocation_link.accept_ticket(invocation_ticket)
        requests = scenario.requests()
        for request_index, request in enumerate(requests):
            request_ticket = links.Ticket(test_operation_id, 1 + request_index,
                                          None, None, None, None, 1, None,
                                          request, None, None, None, None,
                                          None)
            invocation_link.accept_ticket(request_ticket)
            service_mate.block_until_tickets_satisfy(
                test_cases.at_least_n_payloads_received_predicate(
                    1 + request_index))
            response_ticket = links.Ticket(
                service_mate.tickets()[0].operation_id, request_index, None,
                None, None, None, 1, None,
                scenario.response_for_request(request), None, None, None, None,
                None)
            service_link.accept_ticket(response_ticket)
            invocation_mate.block_until_tickets_satisfy(
                test_cases.at_least_n_payloads_received_predicate(
                    1 + request_index))
        request_count = len(requests)
        invocation_completion_ticket = links.Ticket(
            test_operation_id, request_count + 1, None, None, None, None, None,
            None, None, None, None, None, links.Ticket.Termination.COMPLETION,
            None)
        invocation_link.accept_ticket(invocation_completion_ticket)
        service_mate.block_until_tickets_satisfy(test_cases.terminated)
        service_completion_ticket = links.Ticket(
            service_mate.tickets()[0].operation_id, request_count, None, None,
            None, None, None, None, None, None, test_code, test_message,
            links.Ticket.Termination.COMPLETION, None)
        service_link.accept_ticket(service_completion_ticket)
        invocation_mate.block_until_tickets_satisfy(test_cases.terminated)

        invocation_link.stop()
        service_link.begin_stop()
        service_link.end_stop()

        observed_requests = tuple(ticket.payload
                                  for ticket in service_mate.tickets()
                                  if ticket.payload is not None)
        observed_responses = tuple(ticket.payload
                                   for ticket in invocation_mate.tickets()
                                   if ticket.payload is not None)
        self.assertTrue(scenario.verify_requests(observed_requests))
        self.assertTrue(scenario.verify_responses(observed_responses))