Search in sources :

Example 1 with BlockingTesterClient

use of io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method secureClientToSecureServerWithoutPeerHostSucceeds.

@Test
void secureClientToSecureServerWithoutPeerHostSucceeds() throws Exception {
    try (ServerContext serverContext = secureGrpcServer();
        BlockingTesterClient client = secureGrpcClient(serverContext, new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(null).hostnameVerificationAlgorithm(""), false).buildBlocking(clientFactory())) {
        final TesterProto.TestResponse response = client.test(REQUEST);
        assertThat(response, is(notNullValue()));
        assertThat(response.getMessage(), is(notNullValue()));
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Example 2 with BlockingTesterClient

use of io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient 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 BlockingTesterClient

use of io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient 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))));
        }
    }
}
Also used : TesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) ExecutionException(java.util.concurrent.ExecutionException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient)

Example 4 with BlockingTesterClient

use of io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient 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 5 with BlockingTesterClient

use of io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient in project servicetalk by apple.

the class GrpcRouterConfigurationTest method testMissedRouteThrowsUnimplementedException.

@Test
void testMissedRouteThrowsUnimplementedException() throws Exception {
    BlockingTesterClient client = createGrpcClient(startGrpcServer(new ServiceFactory.Builder().test(DEFAULT_STRATEGY_ASYNC_SERVICE).build()));
    TesterProto.TestResponse response = client.test(REQUEST);
    assertThat(response, is(notNullValue()));
    assertThat(response.getMessage(), is(notNullValue()));
    Throwable t = assertThrows(GrpcStatusException.class, () -> client.testRequestStream(singletonList(REQUEST)));
    assertThat(t.getMessage(), equalTo(UNIMPLEMENTED.name()));
}
Also used : BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Aggregations

BlockingTesterClient (io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient)9 ServerContext (io.servicetalk.transport.api.ServerContext)7 Test (org.junit.jupiter.api.Test)7 GrpcStatusException (io.servicetalk.grpc.api.GrpcStatusException)5 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)5 GrpcClientBuilder (io.servicetalk.grpc.api.GrpcClientBuilder)3 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)3 HostAndPort (io.servicetalk.transport.api.HostAndPort)3 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)3 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)3 StacklessClosedChannelException (io.servicetalk.transport.netty.internal.StacklessClosedChannelException)3 InetSocketAddress (java.net.InetSocketAddress)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)3 Matchers.is (org.hamcrest.Matchers.is)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3 DEFAULT_STRATEGY_ASYNC_SERVICE (io.servicetalk.grpc.netty.ExecutionStrategyTestServices.DEFAULT_STRATEGY_ASYNC_SERVICE)2 TesterClient (io.servicetalk.grpc.netty.TesterProto.Tester.TesterClient)2 DefaultTestCerts.serverPemHostname (io.servicetalk.test.resources.DefaultTestCerts.serverPemHostname)2