Search in sources :

Example 1 with TestRequest

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

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

the class SingleRequestOrResponseApiTest method serverResponseStreamingRouteFailsWithInvalidArgument.

private void serverResponseStreamingRouteFailsWithInvalidArgument(Iterable<TestRequest> requestItems, String expectedMsg) throws Exception {
    // No need to run the test with different client-side, always use blocking client
    assumeFalse(streamingClient);
    try (BlockingTesterClient client = newBlockingClient()) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.testBiDiStream(requestItems).forEach(response -> {
        /* noop */
        }));
        assertThat(e.status().code(), is(INVALID_ARGUMENT));
        assertThat(e.status().description(), equalTo(expectedMsg));
    }
}
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) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient)

Aggregations

TestRequest (io.servicetalk.grpc.netty.TesterProto.TestRequest)2 ClientFactory (io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory)2 ServiceFactory (io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory)2 HostAndPort (io.servicetalk.transport.api.HostAndPort)2 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)2 InetSocketAddress (java.net.InetSocketAddress)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 GrpcStatusException (io.servicetalk.grpc.api.GrpcStatusException)1 TestResponse (io.servicetalk.grpc.netty.TesterProto.TestResponse)1 BlockingTestResponseStreamRpc (io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTestResponseStreamRpc)1 BlockingTesterClient (io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient)1