Search in sources :

Example 6 with ServiceFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory in project servicetalk by apple.

the class SingleRequestOrResponseApiTest method setUp.

private void setUp(boolean streamingService, boolean streamingClient) throws Exception {
    this.streamingService = streamingService;
    this.streamingClient = streamingClient;
    serverContext = GrpcServers.forAddress(localAddress(0)).listenAndAwait(streamingService ? new ServiceFactory(new TesterServiceImpl()) : new ServiceFactory(new BlockingTesterServiceImpl()));
    clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(origin -> new StreamingHttpClientFilter(origin) {

        @Override
        protected Single<StreamingHttpResponse> request(StreamingHttpRequester delegate, StreamingHttpRequest request) {
            // and generates requested number of response items:
            return defer(() -> {
                request.requestTarget(BlockingTestResponseStreamRpc.PATH);
                return delegate.request(request).shareContextOnSubscribe();
            });
        }
    }));
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Publisher(io.servicetalk.concurrent.api.Publisher) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) Collections.singletonList(java.util.Collections.singletonList) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) INVALID_ARGUMENT(io.servicetalk.grpc.api.GrpcStatusCode.INVALID_ARGUMENT) ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) Arrays.asList(java.util.Arrays.asList) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) TesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) Publisher.fromIterable(io.servicetalk.concurrent.api.Publisher.fromIterable) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoSuchElementException(java.util.NoSuchElementException) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) Nullable(javax.annotation.Nullable) MethodSource(org.junit.jupiter.params.provider.MethodSource) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Single.defer(io.servicetalk.concurrent.api.Single.defer) Collections.emptyList(java.util.Collections.emptyList) Single(io.servicetalk.concurrent.api.Single) GrpcPayloadWriter(io.servicetalk.grpc.api.GrpcPayloadWriter) TesterService(io.servicetalk.grpc.netty.TesterProto.Tester.TesterService) TestRequest(io.servicetalk.grpc.netty.TesterProto.TestRequest) ClientFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) GrpcServiceContext(io.servicetalk.grpc.api.GrpcServiceContext) BlockingIterable(io.servicetalk.concurrent.BlockingIterable) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) BlockingTestResponseStreamRpc(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTestResponseStreamRpc) BlockingTesterService(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterService) TestResponse(io.servicetalk.grpc.netty.TesterProto.TestResponse) GrpcClientBuilder(io.servicetalk.grpc.api.GrpcClientBuilder) HostAndPort(io.servicetalk.transport.api.HostAndPort) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) Single(io.servicetalk.concurrent.api.Single) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest)

Example 7 with ServiceFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory in project servicetalk by apple.

the class ErrorHandlingTest method setupForServiceSecondOperatorThrows.

private ServiceFactory setupForServiceSecondOperatorThrows(final Throwable toThrow) {
    final TesterService service = mockTesterService();
    setupForServiceSecondOperatorThrows(service, toThrow);
    return new ServiceFactory(service);
}
Also used : ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) TesterService(io.servicetalk.grpc.netty.TesterProto.Tester.TesterService) BlockingTesterService(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterService)

Example 8 with ServiceFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory in project servicetalk by apple.

the class ExecutionStrategyTest method setUp.

private void setUp(ContextExecutionStrategy contextStrategy, RouteExecutionStrategy routeStrategy, RouteApi routeApi) throws Exception {
    this.contextStrategy = contextStrategy;
    this.routeStrategy = routeStrategy;
    this.routeApi = routeApi;
    GrpcServerBuilder builder = GrpcServers.forAddress(localAddress(0));
    contextStrategy.configureContextExecutionStrategy(builder);
    ServiceFactory serviceFactory = routeStrategy.getServiceFactory();
    serverContext = builder.listenAndAwait(serviceFactory);
    client = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(b -> b.executionStrategy(HttpExecutionStrategies.offloadNever())).buildBlocking(new ClientFactory());
}
Also used : GrpcServerBuilder(io.servicetalk.grpc.api.GrpcServerBuilder) ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) ClientFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory)

Example 9 with ServiceFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory in project servicetalk by apple.

the class GrpcServiceContextProtocolTest method setUp.

private void setUp(HttpProtocolVersion httpProtocol, boolean streamingService) throws Exception {
    expectedValue = "gRPC over " + httpProtocol;
    serverContext = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.protocols(protocolConfig(httpProtocol))).listenAndAwait(streamingService ? new ServiceFactory(new TesterServiceImpl()) : new ServiceFactory(new BlockingTesterServiceImpl()));
    client = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.protocols(protocolConfig(httpProtocol))).buildBlocking(new ClientFactory());
}
Also used : ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) ClientFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory)

Example 10 with ServiceFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory in project servicetalk by apple.

the class KeepAliveTest method setUp.

private void setUp(final boolean keepAlivesFromClient, final Duration keepAliveIdleFor, final Duration idleTimeout) throws Exception {
    this.idleTimeoutMillis = idleTimeout.toMillis();
    GrpcServerBuilder serverBuilder = forAddress(localAddress(0)).initializeHttp(builder -> {
        builder.executor(SERVER_CTX.executor()).ioExecutor(SERVER_CTX.ioExecutor()).executionStrategy(defaultStrategy());
        if (!keepAlivesFromClient) {
            builder.protocols(h2Config(keepAliveIdleFor));
        } else {
            builder.socketOption(IDLE_TIMEOUT, idleTimeoutMillis).protocols(h2Config(null));
        }
    });
    ctx = serverBuilder.listenAndAwait(new ServiceFactory(new InfiniteStreamsService()));
    GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(ctx)).initializeHttp(builder -> builder.executor(CLIENT_CTX.executor()).ioExecutor(CLIENT_CTX.ioExecutor()).executionStrategy(defaultStrategy()));
    if (keepAlivesFromClient) {
        clientBuilder.initializeHttp(builder -> builder.protocols(h2Config(keepAliveIdleFor)));
    } else {
        clientBuilder.initializeHttp(builder -> builder.socketOption(IDLE_TIMEOUT, idleTimeoutMillis).protocols(h2Config(null)));
    }
    client = clientBuilder.build(new ClientFactory());
}
Also used : GrpcServerBuilder(io.servicetalk.grpc.api.GrpcServerBuilder) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) InetSocketAddress(java.net.InetSocketAddress) ClientFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory)

Aggregations

ServiceFactory (io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory)14 BlockingTesterService (io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterService)10 TesterService (io.servicetalk.grpc.netty.TesterProto.Tester.TesterService)7 ClientFactory (io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory)5 HostAndPort (io.servicetalk.transport.api.HostAndPort)3 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)3 InetSocketAddress (java.net.InetSocketAddress)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 GrpcServerBuilder (io.servicetalk.grpc.api.GrpcServerBuilder)2 TestRequest (io.servicetalk.grpc.netty.TesterProto.TestRequest)2 BlockingIterable (io.servicetalk.concurrent.BlockingIterable)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)1 Publisher.fromIterable (io.servicetalk.concurrent.api.Publisher.fromIterable)1 Single (io.servicetalk.concurrent.api.Single)1 Single.defer (io.servicetalk.concurrent.api.Single.defer)1 GrpcClientBuilder (io.servicetalk.grpc.api.GrpcClientBuilder)1 GrpcPayloadWriter (io.servicetalk.grpc.api.GrpcPayloadWriter)1 GrpcServiceContext (io.servicetalk.grpc.api.GrpcServiceContext)1 INVALID_ARGUMENT (io.servicetalk.grpc.api.GrpcStatusCode.INVALID_ARGUMENT)1