Exemplo n.º 1
0
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    service = 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()}

    server_options = implementations.server_options(
        request_deserializers=serialization_behaviors.request_deserializers,
        response_serializers=serialization_behaviors.response_serializers,
        thread_pool_size=test_constants.POOL_SIZE)
    server = implementations.server(
        method_implementations, options=server_options)
    server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = server.add_secure_port('[::]:0', server_credentials)
    server.start()
    client_credentials = implementations.ssl_client_credentials(
        resources.test_root_certificates(), None, None)
    channel = test_utilities.not_really_secure_channel(
        'localhost', port, client_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = implementations.stub_options(
        request_serializers=serialization_behaviors.request_serializers,
        response_deserializers=serialization_behaviors.response_deserializers,
        thread_pool_size=test_constants.POOL_SIZE)
    generic_stub = implementations.generic_stub(channel, options=stub_options)
    dynamic_stub = implementations.dynamic_stub(
        channel, service, cardinalities, options=stub_options)
    return generic_stub, {service: dynamic_stub}, server
Exemplo n.º 2
0
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    service = 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()}

    server_options = beta.server_options(
        request_deserializers=serialization_behaviors.request_deserializers,
        response_serializers=serialization_behaviors.response_serializers,
        thread_pool_size=test_constants.POOL_SIZE)
    server = beta.server(method_implementations, options=server_options)
    server_credentials = beta.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = server.add_secure_port('[::]:0', server_credentials)
    server.start()
    client_credentials = beta.ssl_client_credentials(
        resources.test_root_certificates(), None, None)
    channel = test_utilities.create_not_really_secure_channel(
        'localhost', port, client_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = beta.stub_options(
        request_serializers=serialization_behaviors.request_serializers,
        response_deserializers=serialization_behaviors.response_deserializers,
        thread_pool_size=test_constants.POOL_SIZE)
    generic_stub = beta.generic_stub(channel, options=stub_options)
    dynamic_stub = beta.dynamic_stub(
        channel, service, cardinalities, options=stub_options)
    return generic_stub, {service: dynamic_stub}, server
Exemplo n.º 3
0
    def setUp(self):
        self._servicer = _Servicer()
        method_implementations = {
            (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
            (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
            (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
            (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
        }

        cardinalities = {
            _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
            _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
            _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
            _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
        }

        server_options = implementations.server_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._server = implementations.server(method_implementations,
                                              options=server_options)
        server_credentials = implementations.ssl_server_credentials([
            (
                resources.private_key(),
                resources.certificate_chain(),
            ),
        ])
        port = self._server.add_secure_port('[::]:0', server_credentials)
        self._server.start()
        self._client_credentials = implementations.ssl_client_credentials(
            resources.test_root_certificates(), None, None)
        channel = test_utilities.not_really_secure_channel(
            'localhost', port, self._client_credentials, _SERVER_HOST_OVERRIDE)
        stub_options = implementations.stub_options(
            thread_pool_size=test_constants.POOL_SIZE)
        self._dynamic_stub = implementations.dynamic_stub(channel,
                                                          _GROUP,
                                                          cardinalities,
                                                          options=stub_options)
Exemplo n.º 4
0
  def setUp(self):
    self._servicer = _Servicer()
    method_implementations = {
        (_GROUP, _UNARY_UNARY):
            utilities.unary_unary_inline(self._servicer.unary_unary),
        (_GROUP, _UNARY_STREAM):
            utilities.unary_stream_inline(self._servicer.unary_stream),
        (_GROUP, _STREAM_UNARY):
            utilities.stream_unary_inline(self._servicer.stream_unary),
        (_GROUP, _STREAM_STREAM):
            utilities.stream_stream_inline(self._servicer.stream_stream),
    }

    cardinalities = {
        _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
        _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
        _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
        _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
    }

    server_options = implementations.server_options(
        thread_pool_size=test_constants.POOL_SIZE)
    self._server = implementations.server(
        method_implementations, options=server_options)
    server_credentials = implementations.ssl_server_credentials(
        [(resources.private_key(), resources.certificate_chain(),),])
    port = self._server.add_secure_port('[::]:0', server_credentials)
    self._server.start()
    self._client_credentials = implementations.ssl_client_credentials(
        resources.test_root_certificates(), None, None)
    channel = test_utilities.not_really_secure_channel(
        'localhost', port, self._client_credentials, _SERVER_HOST_OVERRIDE)
    stub_options = implementations.stub_options(
        thread_pool_size=test_constants.POOL_SIZE)
    self._dynamic_stub = implementations.dynamic_stub(
        channel, _GROUP, cardinalities, options=stub_options)