use of io.servicetalk.grpc.api.GrpcClientBuilder in project servicetalk by apple.
the class TrailersOnlyErrorTest method testServiceThrows.
@Test
void testServiceThrows() throws Exception {
final BlockingQueue<Throwable> asyncErrors = new LinkedBlockingDeque<>();
final TesterService service = mockTesterService();
setupServiceThrows(service);
try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).listenAndAwait(new Tester.ServiceFactory(service))) {
final GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(__ -> true, setupResponseVerifierFilter(asyncErrors)));
try (TesterClient client = clientBuilder.build(new Tester.ClientFactory())) {
verifyException(client.test(TestRequest.newBuilder().build()).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testRequestStream(Publisher.from(TestRequest.newBuilder().build())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testBiDiStream(from(TestRequest.newBuilder().build()).concat(never())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testBiDiStream(from(TestRequest.newBuilder().build())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
}
}
}
use of io.servicetalk.grpc.api.GrpcClientBuilder in project servicetalk by apple.
the class TrailersOnlyErrorTest method testRouteThrows.
@Test
void testRouteThrows() throws Exception {
final BlockingQueue<Throwable> asyncErrors = new LinkedBlockingDeque<>();
try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).listenAndAwait(new Tester.ServiceFactory(mockTesterService()))) {
final GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(__ -> true, setupResponseVerifierFilter(asyncErrors)));
// thus no route is found and it should result in UNIMPLEMENTED.
try (GreeterClient client = clientBuilder.build(new Greeter.ClientFactory())) {
verifyException(client.sayHello(HelloRequest.newBuilder().build()).toFuture(), UNIMPLEMENTED);
assertNoAsyncErrors(asyncErrors);
}
}
}
use of io.servicetalk.grpc.api.GrpcClientBuilder in project servicetalk by apple.
the class TrailersOnlyErrorTest method testServiceSingleThrows.
@Test
void testServiceSingleThrows() throws Exception {
final BlockingQueue<Throwable> asyncErrors = new LinkedBlockingDeque<>();
final TesterService service = mockTesterService();
setupServiceSingleThrows(service);
try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).listenAndAwait(new Tester.ServiceFactory(service))) {
final GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(__ -> true, setupResponseVerifierFilter(asyncErrors)));
try (TesterClient client = clientBuilder.build(new Tester.ClientFactory())) {
verifyException(client.test(TestRequest.newBuilder().build()).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
}
}
}
use of io.servicetalk.grpc.api.GrpcClientBuilder in project servicetalk by apple.
the class TrailersOnlyErrorTest method testServiceFilterThrows.
@Test
void testServiceFilterThrows() throws Exception {
final BlockingQueue<Throwable> asyncErrors = new LinkedBlockingDeque<>();
final TesterService service = mockTesterService();
final GrpcServerBuilder serverBuilder = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.appendServiceFilter(svc -> new StreamingHttpServiceFilter(svc) {
@Override
public Single<StreamingHttpResponse> handle(final HttpServiceContext ctx, final StreamingHttpRequest request, final StreamingHttpResponseFactory responseFactory) {
throw DELIBERATE_EXCEPTION;
}
}));
try (ServerContext serverContext = serverBuilder.listenAndAwait(new Tester.ServiceFactory(service))) {
final GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(__ -> true, setupResponseVerifierFilter(asyncErrors)));
try (TesterClient client = clientBuilder.build(new Tester.ClientFactory())) {
verifyException(client.test(TestRequest.newBuilder().build()).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testRequestStream(Publisher.from(TestRequest.newBuilder().build())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testResponseStream(TestRequest.newBuilder().build()).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testBiDiStream(from(TestRequest.newBuilder().build()).concat(never())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testBiDiStream(from(TestRequest.newBuilder().build())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
}
}
}
Aggregations