Search in sources :

Example 1 with GrpcStatusException

use of io.servicetalk.grpc.api.GrpcStatusException in project servicetalk by apple.

the class GrpcLifecycleObserverTest method runTest.

private void runTest(Callable<String> executeRequest, boolean error, boolean aggregated) throws Exception {
    setUp(error);
    if (error) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, executeRequest::call);
        assertThat(e.status().code(), is(UNKNOWN));
    } else {
        assertThat(executeRequest.call(), equalTo(CONTENT));
    }
    bothTerminate.await();
    verifyObservers(true, error, aggregated, clientLifecycleObserver, clientExchangeObserver, clientRequestObserver, clientResponseObserver, clientInOrder, clientRequestInOrder);
    verifyObservers(false, error, aggregated, serverLifecycleObserver, serverExchangeObserver, serverRequestObserver, serverResponseObserver, serverInOrder, serverRequestInOrder);
}
Also used : GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException)

Example 2 with GrpcStatusException

use of io.servicetalk.grpc.api.GrpcStatusException in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method nonSecureClientToSecureServerClosesConnection.

@Test
void nonSecureClientToSecureServerClosesConnection() throws Exception {
    try (ServerContext serverContext = secureGrpcServer();
        BlockingTesterClient client = nonSecureGrpcClient(serverContext)) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.test(REQUEST));
        assertThat(e.getCause(), instanceOf(StacklessClosedChannelException.class));
    }
}
Also used : GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) StacklessClosedChannelException(io.servicetalk.transport.netty.internal.StacklessClosedChannelException) Test(org.junit.jupiter.api.Test)

Example 3 with GrpcStatusException

use of io.servicetalk.grpc.api.GrpcStatusException 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));
    }
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Publisher(io.servicetalk.concurrent.api.Publisher) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) Collections.singletonList(java.util.Collections.singletonList) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) INVALID_ARGUMENT(io.servicetalk.grpc.api.GrpcStatusCode.INVALID_ARGUMENT) ServiceFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ServiceFactory) Arrays.asList(java.util.Arrays.asList) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) TesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) Publisher.fromIterable(io.servicetalk.concurrent.api.Publisher.fromIterable) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoSuchElementException(java.util.NoSuchElementException) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) Nullable(javax.annotation.Nullable) MethodSource(org.junit.jupiter.params.provider.MethodSource) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Single.defer(io.servicetalk.concurrent.api.Single.defer) Collections.emptyList(java.util.Collections.emptyList) Single(io.servicetalk.concurrent.api.Single) GrpcPayloadWriter(io.servicetalk.grpc.api.GrpcPayloadWriter) TesterService(io.servicetalk.grpc.netty.TesterProto.Tester.TesterService) TestRequest(io.servicetalk.grpc.netty.TesterProto.TestRequest) ClientFactory(io.servicetalk.grpc.netty.TesterProto.Tester.ClientFactory) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) GrpcServiceContext(io.servicetalk.grpc.api.GrpcServiceContext) BlockingIterable(io.servicetalk.concurrent.BlockingIterable) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) BlockingTestResponseStreamRpc(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTestResponseStreamRpc) BlockingTesterService(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterService) TestResponse(io.servicetalk.grpc.netty.TesterProto.TestResponse) GrpcClientBuilder(io.servicetalk.grpc.api.GrpcClientBuilder) HostAndPort(io.servicetalk.transport.api.HostAndPort) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient)

Example 4 with GrpcStatusException

use of io.servicetalk.grpc.api.GrpcStatusException in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method noSniClientDefaultServerFallbackFailExpected.

@Test
void noSniClientDefaultServerFallbackFailExpected() throws Exception {
    try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.sslConfig(untrustedServerConfig(), singletonMap(getLoopbackAddress().getHostName(), trustedServerConfig()))).listenAndAwait(serviceFactory());
        BlockingTesterClient client = GrpcClients.forAddress(getLoopbackAddress().getHostName(), serverHostAndPort(serverContext).port()).initializeHttp(builder -> builder.sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).build()).inferPeerHost(false).inferSniHostname(false)).buildBlocking(clientFactory())) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.test(REQUEST));
        assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
    }
}
Also used : BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ServerSslConfigBuilder(io.servicetalk.transport.api.ServerSslConfigBuilder) InetSocketAddress(java.net.InetSocketAddress) DefaultTestCerts.serverPemHostname(io.servicetalk.test.resources.DefaultTestCerts.serverPemHostname) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerSslConfig(io.servicetalk.transport.api.ServerSslConfig) DEFAULT_STRATEGY_ASYNC_SERVICE(io.servicetalk.grpc.netty.ExecutionStrategyTestServices.DEFAULT_STRATEGY_ASYNC_SERVICE) StacklessClosedChannelException(io.servicetalk.transport.netty.internal.StacklessClosedChannelException) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GrpcClientBuilder(io.servicetalk.grpc.api.GrpcClientBuilder) HostAndPort(io.servicetalk.transport.api.HostAndPort) InetAddress.getLoopbackAddress(java.net.InetAddress.getLoopbackAddress) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Example 5 with GrpcStatusException

use of io.servicetalk.grpc.api.GrpcStatusException in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method secureClientToNonSecureServerClosesConnection.

@Test
void secureClientToNonSecureServerClosesConnection() throws Exception {
    try (ServerContext serverContext = nonSecureGrpcServer();
        BlockingTesterClient client = secureGrpcClient(serverContext, new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(serverPemHostname())).buildBlocking(clientFactory())) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.test(REQUEST));
        assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
    }
}
Also used : GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Aggregations

GrpcStatusException (io.servicetalk.grpc.api.GrpcStatusException)5 BlockingTesterClient (io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient)4 ServerContext (io.servicetalk.transport.api.ServerContext)4 Test (org.junit.jupiter.api.Test)3 GrpcClientBuilder (io.servicetalk.grpc.api.GrpcClientBuilder)2 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)2 HostAndPort (io.servicetalk.transport.api.HostAndPort)2 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)2 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)2 InetSocketAddress (java.net.InetSocketAddress)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)2 Matchers.is (org.hamcrest.Matchers.is)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 BlockingIterable (io.servicetalk.concurrent.BlockingIterable)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)1 Publisher.fromIterable (io.servicetalk.concurrent.api.Publisher.fromIterable)1 Single (io.servicetalk.concurrent.api.Single)1