Search in sources :

Example 21 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class AbstractHttpServiceAsyncContextTest method connectionAcceptorContextDoesNotLeak.

final void connectionAcceptorContextDoesNotLeak(boolean serverUseImmediate) throws Exception {
    try (ServerContext ctx = serverWithEmptyAsyncContextService(HttpServers.forAddress(localAddress(0)).appendConnectionAcceptorFilter(original -> new DelegatingConnectionAcceptor(context -> {
        AsyncContext.put(K1, "v1");
        return completed();
    })), serverUseImmediate);
        StreamingHttpClient client = HttpClients.forResolvedAddress(serverHostAndPort(ctx)).buildStreaming();
        StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
        makeClientRequestWithId(connection, "1");
        makeClientRequestWithId(connection, "2");
    }
}
Also used : StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) StreamingHttpServiceFilterFactory(io.servicetalk.http.api.StreamingHttpServiceFilterFactory) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString) Thread.currentThread(java.lang.Thread.currentThread) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Key.newKey(io.servicetalk.context.api.ContextMap.Key.newKey) StreamingHttpServiceFilter(io.servicetalk.http.api.StreamingHttpServiceFilter) HttpServiceContext(io.servicetalk.http.api.HttpServiceContext) AsyncContext(io.servicetalk.concurrent.api.AsyncContext) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) CyclicBarrier(java.util.concurrent.CyclicBarrier) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) Matchers.empty(org.hamcrest.Matchers.empty) ServerContext(io.servicetalk.transport.api.ServerContext) HttpProtocolConfigs.h1(io.servicetalk.http.netty.HttpProtocolConfigs.h1) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) Single.defer(io.servicetalk.concurrent.api.Single.defer) PublisherSource(io.servicetalk.concurrent.PublisherSource) Single(io.servicetalk.concurrent.api.Single) OK(io.servicetalk.http.api.HttpResponseStatus.OK) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) HttpClients.forResolvedAddress(io.servicetalk.http.netty.HttpClients.forResolvedAddress) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) CountDownLatch(java.util.concurrent.CountDownLatch) ContextMap(io.servicetalk.context.api.ContextMap) DelegatingConnectionAcceptor(io.servicetalk.transport.api.DelegatingConnectionAcceptor) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) Queue(java.util.Queue) HostAndPort(io.servicetalk.transport.api.HostAndPort) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HttpExecutionStrategies.offloadNever(io.servicetalk.http.api.HttpExecutionStrategies.offloadNever) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) ServerContext(io.servicetalk.transport.api.ServerContext) DelegatingConnectionAcceptor(io.servicetalk.transport.api.DelegatingConnectionAcceptor) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection)

Example 22 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class TracingHttpServiceFilterTest method testRequestWithTraceKeyWithNegativeSampledAndAlwaysTrueSampler.

@Test
void testRequestWithTraceKeyWithNegativeSampledAndAlwaysTrueSampler() throws Exception {
    final CountingInMemorySpanEventListener spanListener = new CountingInMemorySpanEventListener();
    try (ServerContext context = buildServer(spanListener, (__, ___) -> true)) {
        try (HttpClient client = forSingleAddress(serverHostAndPort(context)).build()) {
            String traceId = randomHexId();
            String spanId = randomHexId();
            String requestUrl = "/";
            HttpRequest request = client.get(requestUrl);
            request.headers().set(TRACE_ID, traceId).set(SPAN_ID, spanId).set(SAMPLED, "0");
            HttpResponse response = client.request(request).toFuture().get();
            TestSpanState serverSpanState = response.payloadBody(SPAN_STATE_SERIALIZER);
            assertSpan(spanListener, traceId, spanId, requestUrl, serverSpanState, true);
        }
    }
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ServerContext(io.servicetalk.transport.api.ServerContext) HttpClient(io.servicetalk.http.api.HttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) CountingInMemorySpanEventListener(io.servicetalk.opentracing.http.TestUtils.CountingInMemorySpanEventListener) Test(org.junit.jupiter.api.Test)

Example 23 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class TracingHttpRequesterFilterTest method tracerThrowsReturnsErrorResponse.

@Test
void tracerThrowsReturnsErrorResponse() throws Exception {
    when(mockTracer.buildSpan(any())).thenThrow(DELIBERATE_EXCEPTION);
    try (ServerContext context = buildServer()) {
        try (HttpClient client = forSingleAddress(serverHostAndPort(context)).appendConnectionFilter(new TracingHttpRequesterFilter(mockTracer, "testClient")).build()) {
            HttpRequest request = client.get("/");
            ExecutionException ex = assertThrows(ExecutionException.class, () -> client.request(request).toFuture().get());
            assertThat(ex.getCause(), is(DELIBERATE_EXCEPTION));
        }
    }
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ServerContext(io.servicetalk.transport.api.ServerContext) FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) HttpClient(io.servicetalk.http.api.HttpClient) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 24 with ServerContext

use of io.servicetalk.transport.api.ServerContext 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 25 with ServerContext

use of io.servicetalk.transport.api.ServerContext 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)

Aggregations

ServerContext (io.servicetalk.transport.api.ServerContext)87 Test (org.junit.jupiter.api.Test)40 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)32 HttpResponse (io.servicetalk.http.api.HttpResponse)29 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)28 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)27 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)24 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)23 MethodSource (org.junit.jupiter.params.provider.MethodSource)20 Single (io.servicetalk.concurrent.api.Single)18 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)17 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)17 InetSocketAddress (java.net.InetSocketAddress)17 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)14 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)13 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)13 StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)12 Matchers.is (org.hamcrest.Matchers.is)12