use of reactor.netty.tcp.SslProvider.ProtocolSslContextSpec in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testServerConnectionsRecorder.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testServerConnectionsRecorder(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, () -> ServerRecorder.INSTANCE, Function.identity()).bindNow();
String address = formatSocketAddress(disposableServer.address());
CountDownLatch latch = new CountDownLatch(1);
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols);
httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).metrics(true, Function.identity()).post().uri("/5").send(body).responseContent().aggregate().asString().as(StepVerifier::create).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(ServerRecorder.INSTANCE.done.await(30, TimeUnit.SECONDS)).as("recorder latch await").isTrue();
assertThat(ServerRecorder.INSTANCE.onServerConnectionsAmount.get()).isEqualTo(0);
assertThat(ServerRecorder.INSTANCE.onActiveConnectionsAmount.get()).isEqualTo(0);
assertThat(ServerRecorder.INSTANCE.onActiveConnectionsLocalAddr.get()).isEqualTo(address);
assertThat(ServerRecorder.INSTANCE.onInactiveConnectionsLocalAddr.get()).isEqualTo(address);
disposableServer.disposeNow();
}
use of reactor.netty.tcp.SslProvider.ProtocolSslContextSpec in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testUriTagValueFunction.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testUriTagValueFunction(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, s -> "testUriTagValueResolver").bindNow();
AtomicReference<SocketAddress> serverAddress = new AtomicReference<>();
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols).doAfterRequest((req, conn) -> serverAddress.set(conn.channel().remoteAddress()));
CountDownLatch latch1 = new CountDownLatch(1);
StepVerifier.create(httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch1.countDown())).metrics(true, s -> "testUriTagValueResolver").post().uri("/1").send(body).responseContent().aggregate().asString()).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
InetSocketAddress sa = (InetSocketAddress) serverAddress.get();
Thread.sleep(1000);
checkExpectationsExisting("testUriTagValueResolver", sa.getHostString() + ":" + sa.getPort(), 1, serverCtx != null);
}
use of reactor.netty.tcp.SslProvider.ProtocolSslContextSpec in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testExistingEndpoint.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testExistingEndpoint(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).bindNow();
AtomicReference<SocketAddress> serverAddress = new AtomicReference<>();
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols).doAfterRequest((req, conn) -> serverAddress.set(conn.channel().remoteAddress()));
CountDownLatch latch1 = new CountDownLatch(1);
StepVerifier.create(httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch1.countDown())).post().uri("/1").send(body).responseContent().aggregate().asString()).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch1.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
InetSocketAddress sa = (InetSocketAddress) serverAddress.get();
Thread.sleep(1000);
checkExpectationsExisting("/1", sa.getHostString() + ":" + sa.getPort(), 1, serverCtx != null);
CountDownLatch latch2 = new CountDownLatch(1);
StepVerifier.create(httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch2.countDown())).post().uri("/2?i=1&j=2").send(body).responseContent().aggregate().asString()).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch2.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
sa = (InetSocketAddress) serverAddress.get();
Thread.sleep(1000);
checkExpectationsExisting("/2", sa.getHostString() + ":" + sa.getPort(), 2, serverCtx != null);
}
use of reactor.netty.tcp.SslProvider.ProtocolSslContextSpec in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testContextAwareRecorderOnClient.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testContextAwareRecorderOnClient(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).bindNow();
ClientContextAwareRecorder recorder = ClientContextAwareRecorder.INSTANCE;
CountDownLatch latch = new CountDownLatch(1);
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols);
httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).metrics(true, () -> recorder).post().uri("/1").send(body).responseContent().aggregate().asString().contextWrite(Context.of("testContextAwareRecorder", "OK")).as(StepVerifier::create).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(recorder.onDataReceivedContextView).isTrue();
assertThat(recorder.onDataSentContextView).isTrue();
}
use of reactor.netty.tcp.SslProvider.ProtocolSslContextSpec in project reactor-netty by reactor.
the class HttpMetricsHandlerTests method testContextAwareRecorderOnServer.
@ParameterizedTest
@MethodSource("httpCompatibleProtocols")
void testContextAwareRecorderOnServer(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable ProtocolSslContextSpec serverCtx, @Nullable ProtocolSslContextSpec clientCtx) throws Exception {
ServerContextAwareRecorder recorder = ServerContextAwareRecorder.INSTANCE;
disposableServer = customizeServerOptions(httpServer, serverCtx, serverProtocols).metrics(true, () -> recorder).mapHandle((mono, conn) -> mono.contextWrite(Context.of("testContextAwareRecorder", "OK"))).bindNow();
CountDownLatch latch = new CountDownLatch(1);
httpClient = customizeClientOptions(httpClient, clientCtx, clientProtocols);
httpClient.doOnResponse((res, conn) -> conn.channel().closeFuture().addListener(f -> latch.countDown())).post().uri("/1").send(body).responseContent().aggregate().asString().as(StepVerifier::create).expectNext("Hello World!").expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(recorder.onDataReceivedContextView).isTrue();
assertThat(recorder.onDataSentContextView).isTrue();
}
Aggregations