use of io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient in project servicetalk by apple.
the class CustomTransportTest method testCustomTransport.
@ParameterizedTest
@EnumSource(ServiceType.class)
void testCustomTransport(final ServiceType serviceType) throws Exception {
// You can re-use the EventLoopGroup used by your Netty application, we create one to demonstrate its use.
EventLoopAwareNettyIoExecutor ioExecutor = createIoExecutor("netty-el");
// This is the Netty channel which is reading the request. See getServiceContext(Channel), depending
// upon what control you want to give users knowing this may not be necessary.
Channel c = new EmbeddedChannel();
try {
ServerTransport serverTransport = new InMemoryServerTransport(DEFAULT_ALLOCATOR, serviceType.grpcService);
// Build the client with the custom transport and bridge to server's transport.
Tester.TesterClient client = new Tester.ClientFactory() {
@Override
public TesterClient newClient(final GrpcClientCallFactory factory) {
return super.newClient(factory);
}
}.newClient(new ClientTransportGrpcCallFactory(// Build the client transport, which just calls the server transport directly.
(method, requestMessages) -> serverTransport.handle(c, "clientId", method, requestMessages), ioExecutor.eventLoopGroup()));
// Test using the client.
assertThat(client.test(newReq("scalar")).toFuture().get(), is(newResp("hello scalar")));
assertThat(client.testRequestStream(newReqStream("req")).toFuture().get(), is(newResp("hello reqstream1, reqstream2, ")));
assertThat(client.testResponseStream(newReq("respStream")).toFuture().get(), contains(newResp("hello respStream1"), newResp("hello respStream2")));
assertThat(client.testBiDiStream(newReqStream("duplex")).toFuture().get(), contains(newResp("hello duplexstream1"), newResp("hello duplexstream2")));
} finally {
c.close();
ioExecutor.closeAsync().toFuture().get();
}
}
use of io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient 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.netty.TesterProto.Tester.TesterClient in project servicetalk by apple.
the class SingleRequestOrResponseApiTest method clientRequestStreamingCallFailsOnInvalidResponse.
private <T extends Throwable> void clientRequestStreamingCallFailsOnInvalidResponse(int numberOfResponses, Class<T> exceptionClass) throws Exception {
// No need to run the test with different server-side
assumeFalse(streamingService);
if (streamingClient) {
try (TesterClient client = newClient()) {
ExecutionException e = assertThrows(ExecutionException.class, () -> client.testRequestStream(from(newRequest(numberOfResponses))).toFuture().get());
assertThat(e.getCause(), is(instanceOf(exceptionClass)));
}
} else {
try (BlockingTesterClient client = newBlockingClient()) {
assertThrows(exceptionClass, () -> client.testRequestStream(singletonList(newRequest(numberOfResponses))));
}
}
}
use of io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient 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.netty.TesterProto.Tester.TesterClient 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