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");
}
}
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);
}
}
}
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));
}
}
}
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()));
}
}
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));
}
}
Aggregations