Search in sources :

Example 1 with ServiceFactory

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

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

the class ErrorHandlingTest method setupForServiceEmitsError.

private ServiceFactory setupForServiceEmitsError(final Throwable toThrow) {
    final TesterService service = mockTesterService();
    setupForServiceEmitsError(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 3 with ServiceFactory

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

the class ClosureTest method serviceImplIsClosed.

@ParameterizedTest(name = "graceful? => {0}")
@ValueSource(booleans = { true, false })
void serviceImplIsClosed(final boolean param) throws Exception {
    setUp(param);
    CloseSignal signal = new CloseSignal(1);
    TesterService svc = setupCloseMock(mock(TesterService.class), signal);
    startServerAndClose(new ServiceFactory(svc), signal);
    verifyClosure(svc, 4);
    signal.verifyCloseAtLeastCount(closeGracefully);
}
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) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ServiceFactory

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

the class ErrorHandlingTest method setupForServiceOperatorThrows.

private ServiceFactory setupForServiceOperatorThrows(final Throwable toThrow) {
    final TesterService service = mockTesterService();
    setupForServiceOperatorThrows(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 5 with ServiceFactory

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

the class ErrorHandlingTest method setupForBlockingServiceWritesThenThrows.

private ServiceFactory setupForBlockingServiceWritesThenThrows(final Throwable toThrow) throws Exception {
    final BlockingTesterService blockingService = mock(BlockingTesterService.class);
    setupForBlockingServiceWritesThenThrows(blockingService, toThrow);
    return new ServiceFactory(blockingService);
}
Also used : BlockingTesterService(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterService) ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory)

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