Search in sources :

Example 61 with ServerContext

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);
        }
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) HttpServerContext(io.servicetalk.http.api.HttpServerContext) ServerContext(io.servicetalk.transport.api.ServerContext) PublisherSource(io.servicetalk.concurrent.PublisherSource) BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) Duration(java.time.Duration) IOException(java.io.IOException) CompatRequest(io.servicetalk.grpc.netty.CompatProto.RequestContainer.CompatRequest) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with ServerContext

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);
    }
}
Also used : HttpServerContext(io.servicetalk.http.api.HttpServerContext) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 63 with ServerContext

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));
        }
    }
}
Also used : AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) GrpcServerContext(io.servicetalk.grpc.api.GrpcServerContext) ServerContext(io.servicetalk.transport.api.ServerContext) Greeter(io.grpc.examples.helloworld.Greeter) ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) GrpcClientFactory(io.servicetalk.grpc.api.GrpcClientFactory) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.jupiter.api.Test)

Example 64 with ServerContext

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")));
    }
}
Also used : GrpcServerContext(io.servicetalk.grpc.api.GrpcServerContext) ServerContext(io.servicetalk.transport.api.ServerContext) Greeter(io.grpc.examples.helloworld.Greeter) ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) GrpcClientFactory(io.servicetalk.grpc.api.GrpcClientFactory) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.jupiter.api.Test)

Example 65 with ServerContext

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));
        }
    }
}
Also used : GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) HealthCheckResponse(io.servicetalk.health.v1.HealthCheckResponse) Health(io.servicetalk.health.v1.Health) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Aggregations

ServerContext (io.servicetalk.transport.api.ServerContext)106 Test (org.junit.jupiter.api.Test)57 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)42 HttpResponse (io.servicetalk.http.api.HttpResponse)39 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)33 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)28 InetSocketAddress (java.net.InetSocketAddress)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)26 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 HostAndPort (io.servicetalk.transport.api.HostAndPort)20 Single (io.servicetalk.concurrent.api.Single)19 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)19 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)16 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)15 OK (io.servicetalk.http.api.HttpResponseStatus.OK)14 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)14