use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class ProtocolCompatibilityTest method timeoutMidRequest.
@ParameterizedTest
@CsvSource({ "false,false,false", "false,false,true", "false,true,false", "false,true,true", "true,false,false", "true,false,true", "true,true,false", "true,true,true" })
void timeoutMidRequest(boolean stClient, boolean stServer, boolean clientInitiatedTimeout) throws Exception {
Duration clientTimeout = clientInitiatedTimeout ? DEFAULT_DEADLINE : null;
Duration serverTimeout = clientInitiatedTimeout ? null : DEFAULT_DEADLINE;
BlockingQueue<Throwable> serverErrorQueue = new ArrayBlockingQueue<>(16);
final TestServerContext server = stServer ? serviceTalkServer(ErrorMode.NONE, false, from(offloadNone()), null, null, serverErrorQueue) : grpcJavaServer(ErrorMode.NONE, false, null);
try (ServerContext proxyCtx = buildTimeoutProxy(server.listenAddress(), serverTimeout, false)) {
final CompatClient client = stClient ? serviceTalkClient(proxyCtx.listenAddress(), false, null, clientTimeout) : grpcJavaClient(proxyCtx.listenAddress(), null, false, clientTimeout);
try {
PublisherSource.Processor<CompatRequest, CompatRequest> reqPub = newPublisherProcessor();
reqPub.onNext(CompatRequest.newBuilder().setId(3).build());
validateGrpcErrorInResponse(client.bidirectionalStreamingCall(fromSource(reqPub)).toFuture(), false, clientInitiatedTimeout ? DEADLINE_EXCEEDED : CANCELLED, null);
// It is possible that the timeout on the client occurred before writing the request, in which case the
// server will never request the request, and therefore no error is expected.
Throwable cause = serverErrorQueue.poll(DEFAULT_DEADLINE.toNanos() * 2, NANOSECONDS);
if (cause != null) {
assertThat(cause, is(SERVER_PROCESSED_TOKEN));
cause = serverErrorQueue.take();
assertThat(cause, instanceOf(IOException.class));
}
} finally {
closeAll(server, client);
}
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class ProtocolCompatibilityTest method grpcJavaToGrpcJavaClientTimeout.
@ParameterizedTest
@MethodSource("sslStreamingAndCompressionParams")
void grpcJavaToGrpcJavaClientTimeout(final boolean ssl, final boolean streaming, final String compression) throws Exception {
final TestServerContext server = grpcJavaServer(ErrorMode.NONE, ssl, compression);
try (ServerContext proxyCtx = buildTimeoutProxy(server.listenAddress(), null, ssl)) {
final CompatClient client = grpcJavaClient(proxyCtx.listenAddress(), compression, ssl, DEFAULT_DEADLINE);
testGrpcError(client, server, false, streaming, compression, DEADLINE_EXCEEDED, null);
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class GrpcProvidersTest method testGrpcClientBuilderProvider.
@Test
void testGrpcClientBuilderProvider() throws Exception {
try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).listenAndAwait(BlockingGreeterServiceImpl.INSTANCE)) {
HostAndPort serverAddress = serverHostAndPort(serverContext);
TestGrpcClientBuilderProvider.MODIFY_FOR_ADDRESS.set(serverAddress);
try (Greeter.BlockingGreeterClient client = GrpcClients.forAddress(serverAddress).buildBlocking(new ClientFactory())) {
assertThat(TestGrpcClientBuilderProvider.BUILD_COUNTER.get(), is(1));
HelloReply reply = client.sayHello(HelloRequest.newBuilder().setName("foo").build());
assertThat(reply.getMessage(), is(equalTo("reply to foo")));
assertThat(TestGrpcClientBuilderProvider.CONNECTION_COUNTER.get(), is(1));
}
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class GrpcProvidersTest method testNoProvidersForAddress.
@Test
void testNoProvidersForAddress() throws Exception {
try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).listenAndAwait(BlockingGreeterServiceImpl.INSTANCE);
Greeter.BlockingGreeterClient client = GrpcClients.forAddress(serverHostAndPort(serverContext)).buildBlocking(new ClientFactory())) {
HelloReply reply = client.sayHello(HelloRequest.newBuilder().setName("foo").build());
assertThat(reply.getMessage(), is(equalTo("reply to foo")));
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class DefaultHealthServiceTest method terminateWatchCheck.
@Test
void terminateWatchCheck() throws Exception {
DefaultHealthService service = new DefaultHealthService();
try (ServerContext serverCtx = GrpcServers.forAddress(localAddress(0)).listenAndAwait(service)) {
try (Health.BlockingHealthClient client = GrpcClients.forResolvedAddress((InetSocketAddress) serverCtx.listenAddress()).buildBlocking(new Health.ClientFactory())) {
BlockingIterator<HealthCheckResponse> itr = client.watch(newRequest(OVERALL_SERVICE_NAME)).iterator();
assertThat(itr.next().getStatus(), equalTo(SERVING));
assertThat(client.check(newRequest(OVERALL_SERVICE_NAME)).getStatus(), equalTo(SERVING));
assertThat(service.terminate(), equalTo(true));
assertThat(itr.next().getStatus(), equalTo(NOT_SERVING));
assertThat(itr.hasNext(), equalTo(false));
assertThat(client.check(newRequest(OVERALL_SERVICE_NAME)).getStatus(), equalTo(NOT_SERVING));
assertThat(service.setStatus(OVERALL_SERVICE_NAME, SERVING), equalTo(false));
// Clear after terminate verifies that multiple termination doesn't cause issues.
assertThat(service.clearStatus(OVERALL_SERVICE_NAME), equalTo(true));
assertThat(assertThrows(GrpcStatusException.class, () -> client.check(newRequest(OVERALL_SERVICE_NAME))).status().code(), equalTo(NOT_FOUND));
}
}
}
Aggregations