Search in sources :

Example 1 with ClientFactory

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

the class ErrorHandlingTest method setUp.

private void setUp(TestMode testMode, GrpcExecutionStrategy serverStrategy, GrpcExecutionStrategy clientStrategy) throws Exception {
    this.testMode = testMode;
    cannedResponse = TestResponse.newBuilder().setMessage("foo").build();
    ServiceFactory serviceFactory;
    StreamingHttpServiceFilterFactory serviceFilterFactory = IDENTITY_FILTER;
    StreamingHttpClientFilterFactory clientFilterFactory = IDENTITY_CLIENT_FILTER;
    Publisher<TestRequest> requestPublisher = from(TestRequest.newBuilder().build());
    switch(testMode) {
        case HttpClientFilterThrows:
            clientFilterFactory = new ErrorProducingClientFilter(true, DELIBERATE_EXCEPTION);
            serviceFactory = setupForSuccess();
            break;
        case HttpClientFilterThrowsGrpcException:
            clientFilterFactory = new ErrorProducingClientFilter(true, cannedException);
            serviceFactory = setupForSuccess();
            break;
        case HttpClientFilterEmitsError:
            clientFilterFactory = new ErrorProducingClientFilter(false, DELIBERATE_EXCEPTION);
            serviceFactory = setupForSuccess();
            break;
        case HttpClientFilterEmitsGrpcException:
            clientFilterFactory = new ErrorProducingClientFilter(false, cannedException);
            serviceFactory = setupForSuccess();
            break;
        case HttpFilterThrows:
            serviceFilterFactory = new ErrorProducingSvcFilter(true, DELIBERATE_EXCEPTION);
            serviceFactory = setupForSuccess();
            break;
        case HttpFilterThrowsGrpcException:
            serviceFilterFactory = new ErrorProducingSvcFilter(true, cannedException);
            serviceFactory = setupForSuccess();
            break;
        case HttpFilterEmitsError:
            serviceFilterFactory = new ErrorProducingSvcFilter(false, DELIBERATE_EXCEPTION);
            serviceFactory = setupForSuccess();
            break;
        case HttpFilterEmitsGrpcException:
            serviceFilterFactory = new ErrorProducingSvcFilter(false, cannedException);
            serviceFactory = setupForSuccess();
            break;
        case ServiceThrows:
            serviceFactory = setupForServiceThrows(DELIBERATE_EXCEPTION);
            break;
        case ServiceThrowsGrpcException:
            serviceFactory = setupForServiceThrows(cannedException);
            break;
        case ServiceOperatorThrows:
            serviceFactory = setupForServiceOperatorThrows(DELIBERATE_EXCEPTION);
            break;
        case ServiceOperatorThrowsGrpcException:
            serviceFactory = setupForServiceOperatorThrows(cannedException);
            break;
        case ServiceSecondOperatorThrowsGrpcException:
            serviceFactory = setupForServiceSecondOperatorThrows(cannedException);
            requestPublisher = from(TestRequest.newBuilder().build(), TestRequest.newBuilder().setName(REQ_THROW_NAME).build());
            break;
        case ServiceEmitsError:
            serviceFactory = setupForServiceEmitsError(DELIBERATE_EXCEPTION);
            break;
        case ServiceEmitsGrpcException:
            serviceFactory = setupForServiceEmitsError(cannedException);
            break;
        case ServiceEmitsDataThenError:
            serviceFactory = setupForServiceEmitsDataThenError(DELIBERATE_EXCEPTION);
            break;
        case ServiceEmitsDataThenGrpcException:
            serviceFactory = setupForServiceEmitsDataThenError(cannedException);
            break;
        case BlockingServiceThrows:
            serviceFactory = setupForBlockingServiceThrows(DELIBERATE_EXCEPTION);
            break;
        case BlockingServiceThrowsGrpcException:
            serviceFactory = setupForBlockingServiceThrows(cannedException);
            break;
        case BlockingServiceWritesThenThrows:
            serviceFactory = setupForBlockingServiceWritesThenThrows(DELIBERATE_EXCEPTION);
            break;
        case BlockingServiceWritesThenThrowsGrpcException:
            serviceFactory = setupForBlockingServiceWritesThenThrows(cannedException);
            break;
        default:
            throw new IllegalArgumentException("Unknown mode: " + testMode);
    }
    this.requestPublisher = requestPublisher;
    final StreamingHttpServiceFilterFactory filterFactory = serviceFilterFactory;
    serverContext = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.appendServiceFilter(filterFactory).executionStrategy(serverStrategy)).listenAndAwait(serviceFactory);
    final StreamingHttpClientFilterFactory pickedClientFilterFactory = clientFilterFactory;
    GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(pickedClientFilterFactory).executionStrategy(clientStrategy));
    client = clientBuilder.build(new ClientFactory());
    blockingClient = clientBuilder.buildBlocking(new ClientFactory());
}
Also used : StreamingHttpClientFilterFactory(io.servicetalk.http.api.StreamingHttpClientFilterFactory) 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) StreamingHttpServiceFilterFactory(io.servicetalk.http.api.StreamingHttpServiceFilterFactory) TestRequest(io.servicetalk.grpc.netty.TesterProto.TestRequest)

Example 2 with ClientFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory 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 3 with ClientFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory 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 4 with ClientFactory

use of io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory 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

ClientFactory (io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory)4 ServiceFactory (io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory)4 GrpcServerBuilder (io.servicetalk.grpc.api.GrpcServerBuilder)2 HostAndPort (io.servicetalk.transport.api.HostAndPort)2 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)2 InetSocketAddress (java.net.InetSocketAddress)2 TestRequest (io.servicetalk.grpc.netty.TesterProto.TestRequest)1 StreamingHttpClientFilterFactory (io.servicetalk.http.api.StreamingHttpClientFilterFactory)1 StreamingHttpServiceFilterFactory (io.servicetalk.http.api.StreamingHttpServiceFilterFactory)1