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 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 HttpAuthConnectionFactoryClientTest method simulateAuth.
@Test
void simulateAuth() throws Exception {
serverContext = forAddress(localAddress(0)).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).listenStreamingAndAwait((ctx, request, factory) -> succeeded(newTestResponse(factory)));
client = forSingleAddress(serverHostAndPort(serverContext)).appendConnectionFactoryFilter(TestHttpAuthConnectionFactory::new).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).buildStreaming();
StreamingHttpResponse response = client.request(newTestRequest(client, "/foo")).toFuture().get();
assertEquals(OK, response.status());
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class HttpConnectionContextProtocolTest method testProtocol.
@ParameterizedTest
@EnumSource(Config.class)
void testProtocol(Config config) throws Exception {
try (ServerContext serverContext = startServer(config);
BlockingHttpClient client = newClient(serverContext, config);
BlockingHttpConnection connection = client.reserveConnection(client.get("/"))) {
assertThat("Client-side connection protocol does not match expected value", connection.connectionContext().protocol(), equalTo(config.expectedProtocol));
assertThat("Server-side connection protocol does not match expected value", connection.request(connection.get("/")).payloadBody(textSerializerUtf8()), equalTo(config.expectedProtocol.name()));
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class MutualSslTest method mutualSsl.
@ParameterizedTest
@MethodSource("params")
void mutualSsl(SslProvider serverSslProvider, SslProvider clientSslProvider, @SuppressWarnings("rawtypes") Map<SocketOption, Object> serverListenOptions, @SuppressWarnings("rawtypes") Map<SocketOption, Object> clientOptions) throws Exception {
assumeTcpFastOpen(clientOptions);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0)).sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).trustManager(DefaultTestCerts::loadClientCAPem).clientAuthMode(REQUIRE).provider(serverSslProvider).build());
for (@SuppressWarnings("rawtypes") Entry<SocketOption, Object> entry : serverListenOptions.entrySet()) {
@SuppressWarnings("unchecked") SocketOption<Object> option = entry.getKey();
serverBuilder.listenSocketOption(option, entry.getValue());
}
try (ServerContext serverContext = serverBuilder.listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = newClientBuilder(serverContext, clientOptions).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).provider(clientSslProvider).peerHost(serverPemHostname()).keyManager(DefaultTestCerts::loadClientPem, DefaultTestCerts::loadClientKey).build()).buildBlocking()) {
assertEquals(HttpResponseStatus.OK, client.request(client.get("/")).status());
}
}
Aggregations