コード例 #1
0
  def instantiate(self, serializations, servicer):
    serialization_behaviors = _serialization_behaviors_from_serializations(
        serializations)
    invocation_end_link = implementations.invocation_end_link()
    service_end_link = implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    service_grpc_link = service.service_link(
        serialization_behaviors.request_deserializers,
        serialization_behaviors.response_serializers)
    port = service_grpc_link.add_port('[::]:0', None)
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_grpc_link = invocation.invocation_link(
        channel, b'localhost', None,
        serialization_behaviors.request_serializers,
        serialization_behaviors.response_deserializers)

    invocation_end_link.join_link(invocation_grpc_link)
    invocation_grpc_link.join_link(invocation_end_link)
    service_end_link.join_link(service_grpc_link)
    service_grpc_link.join_link(service_end_link)
    invocation_grpc_link.start()
    service_grpc_link.start()
    return invocation_end_link, service_end_link, (
        invocation_grpc_link, service_grpc_link)
コード例 #2
0
  def instantiate(self, serializations, servicer):
    serialization_behaviors = _serialization_behaviors_from_serializations(
        serializations)
    invocation_end_link = implementations.invocation_end_link()
    service_end_link = implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    service_grpc_link = service.service_link(
        serialization_behaviors.request_deserializers,
        serialization_behaviors.response_serializers)
    port = service_grpc_link.add_port('[::]:0', None)
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_grpc_link = invocation.invocation_link(
        channel, b'localhost', None,
        serialization_behaviors.request_serializers,
        serialization_behaviors.response_deserializers)

    invocation_end_link.join_link(invocation_grpc_link)
    invocation_grpc_link.join_link(invocation_end_link)
    service_end_link.join_link(service_grpc_link)
    service_grpc_link.join_link(service_end_link)
    invocation_grpc_link.start()
    service_grpc_link.start()
    return invocation_end_link, service_end_link, (
        invocation_grpc_link, service_grpc_link)
コード例 #3
0
ファイル: _server.py プロジェクト: venkiteswara/grpc
def server(implementations, multi_implementation, request_deserializers,
           response_serializers, thread_pool, thread_pool_size,
           default_timeout, maximum_timeout):
    if thread_pool is None:
        service_thread_pool = logging_pool.pool(
            _DEFAULT_POOL_SIZE
            if thread_pool_size is None else thread_pool_size)
        assembly_thread_pool = service_thread_pool
    else:
        service_thread_pool = thread_pool
        assembly_thread_pool = None

    servicer = _GRPCServicer(
        _crust_implementations.servicer(implementations, multi_implementation,
                                        service_thread_pool))

    grpc_link = service.service_link(request_deserializers,
                                     response_serializers)

    end_link = _core_implementations.service_end_link(
        servicer,
        _DEFAULT_TIMEOUT if default_timeout is None else default_timeout,
        _MAXIMUM_TIMEOUT if maximum_timeout is None else maximum_timeout)

    return Server(grpc_link, end_link, assembly_thread_pool)
コード例 #4
0
def server(implementations, multi_implementation, request_deserializers,
           response_serializers, thread_pool, thread_pool_size,
           default_timeout, maximum_timeout):
    grpc_link = service.service_link(request_deserializers,
                                     response_serializers)
    return _Server(
        implementations, multi_implementation, thread_pool,
        _DEFAULT_POOL_SIZE if thread_pool_size is None else thread_pool_size,
        _DEFAULT_TIMEOUT if default_timeout is None else default_timeout,
        _MAXIMUM_TIMEOUT if maximum_timeout is None else maximum_timeout,
        grpc_link)
コード例 #5
0
ファイル: _server.py プロジェクト: coreyglory/grpc
def server(
    implementations, multi_implementation, request_deserializers,
    response_serializers, thread_pool, thread_pool_size, default_timeout,
    maximum_timeout):
  grpc_link = service.service_link(request_deserializers, response_serializers)
  return _Server(
      implementations, multi_implementation, thread_pool,
      _DEFAULT_POOL_SIZE if thread_pool_size is None else thread_pool_size,
      _DEFAULT_TIMEOUT if default_timeout is None else default_timeout,
      _MAXIMUM_TIMEOUT if maximum_timeout is None else maximum_timeout,
      grpc_link)
コード例 #6
0
 def create_transmitting_links(self):
   service_link = service.service_link(
       {self.group_and_method(): self.deserialize_request},
       {self.group_and_method(): self.serialize_response})
   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',
       {self.group_and_method(): self.serialize_request},
       {self.group_and_method(): self.deserialize_response})
   invocation_link.start()
   return invocation_link, service_link
コード例 #7
0
ファイル: _transmission_test.py プロジェクト: mindware/grpc
 def create_transmitting_links(self):
     service_link = service.service_link(
         {self.group_and_method(): self.deserialize_request},
         {self.group_and_method(): self.serialize_response})
     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,
         {self.group_and_method(): self.serialize_request},
         {self.group_and_method(): self.deserialize_response})
     invocation_link.start()
     return invocation_link, service_link
    def instantiate(self, methods, method_implementations,
                    multi_method_implementation):
        pool = logging_pool.pool(test_constants.POOL_SIZE)
        servicer = crust_implementations.servicer(method_implementations,
                                                  multi_method_implementation,
                                                  pool)
        serialization_behaviors = _serialization_behaviors_from_test_methods(
            methods)
        invocation_end_link = core_implementations.invocation_end_link()
        service_end_link = core_implementations.service_end_link(
            servicer, test_constants.DEFAULT_TIMEOUT,
            test_constants.MAXIMUM_TIMEOUT)
        service_grpc_link = service.service_link(
            serialization_behaviors.request_deserializers,
            serialization_behaviors.response_serializers)
        port = service_grpc_link.add_port('[::]:0', None)
        channel = _intermediary_low.Channel('localhost:%d' % port, None)
        invocation_grpc_link = invocation.invocation_link(
            channel, b'localhost', None,
            serialization_behaviors.request_serializers,
            serialization_behaviors.response_deserializers)

        invocation_end_link.join_link(invocation_grpc_link)
        invocation_grpc_link.join_link(invocation_end_link)
        service_grpc_link.join_link(service_end_link)
        service_end_link.join_link(service_grpc_link)
        service_end_link.start()
        invocation_end_link.start()
        invocation_grpc_link.start()
        service_grpc_link.start()

        generic_stub = crust_implementations.generic_stub(
            invocation_end_link, pool)
        # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
        group = next(iter(methods))[0]
        # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
        # _digest.TestServiceDigest.
        cardinalities = {
            method: method_object.cardinality()
            for (group, method), method_object in six.iteritems(methods)
        }
        dynamic_stub = crust_implementations.dynamic_stub(
            invocation_end_link, group, cardinalities, pool)

        return generic_stub, {
            group: dynamic_stub
        }, (invocation_end_link, invocation_grpc_link, service_grpc_link,
            service_end_link, pool)
コード例 #9
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)
コード例 #10
0
ファイル: _transmission_test.py プロジェクト: Crusty82/grpc
  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)
コード例 #11
0
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    pool = logging_pool.pool(test_constants.POOL_SIZE)
    servicer = crust_implementations.servicer(
        method_implementations, multi_method_implementation, pool)
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    invocation_end_link = core_implementations.invocation_end_link()
    service_end_link = core_implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    service_grpc_link = service.service_link(
        serialization_behaviors.request_deserializers,
        serialization_behaviors.response_serializers)
    port = service_grpc_link.add_port('[::]:0', None)
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_grpc_link = invocation.invocation_link(
        channel, b'localhost',
        serialization_behaviors.request_serializers,
        serialization_behaviors.response_deserializers)

    invocation_end_link.join_link(invocation_grpc_link)
    invocation_grpc_link.join_link(invocation_end_link)
    service_grpc_link.join_link(service_end_link)
    service_end_link.join_link(service_grpc_link)
    service_end_link.start()
    invocation_end_link.start()
    invocation_grpc_link.start()
    service_grpc_link.start()

    generic_stub = crust_implementations.generic_stub(invocation_end_link, pool)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    group = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in methods.iteritems()}
    dynamic_stub = crust_implementations.dynamic_stub(
        invocation_end_link, group, cardinalities, pool)

    return generic_stub, {group: dynamic_stub}, (
        invocation_end_link, invocation_grpc_link, service_grpc_link,
        service_end_link, pool)
コード例 #12
0
ファイル: _server.py プロジェクト: kevgh/grpc
def server(
    implementations, multi_implementation, request_deserializers,
    response_serializers, thread_pool, thread_pool_size, default_timeout,
    maximum_timeout):
  if thread_pool is None:
    service_thread_pool = logging_pool.pool(
        _DEFAULT_POOL_SIZE if thread_pool_size is None else thread_pool_size)
    assembly_thread_pool = service_thread_pool
  else:
    service_thread_pool = thread_pool
    assembly_thread_pool = None

  servicer = _crust_implementations.servicer(
      implementations, multi_implementation, service_thread_pool)

  grpc_link = service.service_link(request_deserializers, response_serializers)

  end_link = _core_implementations.service_end_link(
      servicer,
      _DEFAULT_TIMEOUT if default_timeout is None else default_timeout,
      _MAXIMUM_TIMEOUT if maximum_timeout is None else maximum_timeout)

  return Server(grpc_link, end_link, assembly_thread_pool)
コード例 #13
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',
        {(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)
    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)
      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)
      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)
    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)
    service_link.accept_ticket(service_completion_ticket)
    invocation_mate.block_until_tickets_satisfy(test_cases.terminated)

    invocation_link.stop()
    service_link.stop_gracefully()

    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))
コード例 #14
0
ファイル: _transmission_test.py プロジェクト: gpndata/grpc
    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 = _intermediary_low.Code.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, "localhost", 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.stop_gracefully()

        self.assertIs(service_mate.tickets()[-1].termination, links.Ticket.Termination.COMPLETION)
        self.assertIs(invocation_mate.tickets()[-1].termination, links.Ticket.Termination.COMPLETION)
コード例 #15
0
ファイル: _transmission_test.py プロジェクト: mindware/grpc
    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))