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());
}
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));
}
}
Aggregations