use of reactor.netty.Metrics.IDLE_CONNECTIONS in project reactor-netty by reactor.
the class PooledConnectionProviderDefaultMetricsTest method doTest.
private void doTest(HttpServer server, HttpClient client, String poolName, boolean clientMetricsEnabled, int expectedMaxConnection, int expectedMaxPendingAcquire) throws Exception {
disposableServer = server.handle((req, res) -> res.header("Connection", "close").sendString(Mono.just("test"))).bindNow();
AtomicBoolean metrics = new AtomicBoolean(false);
CountDownLatch latch = new CountDownLatch(1);
boolean isSecured = client.configuration().sslProvider() != null;
client.doOnResponse((res, conn) -> {
conn.channel().closeFuture().addListener(f -> latch.countDown());
double totalConnections = getGaugeValue(CONNECTION_PROVIDER_PREFIX + TOTAL_CONNECTIONS, poolName);
double activeConnections = getGaugeValue(CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS, poolName);
double maxConnections = getGaugeValue(CONNECTION_PROVIDER_PREFIX + MAX_CONNECTIONS, poolName);
double idleConnections = getGaugeValue(CONNECTION_PROVIDER_PREFIX + IDLE_CONNECTIONS, poolName);
double pendingConnections = getGaugeValue(CONNECTION_PROVIDER_PREFIX + PENDING_CONNECTIONS, poolName);
double maxPendingConnections = getGaugeValue(CONNECTION_PROVIDER_PREFIX + MAX_PENDING_CONNECTIONS, poolName);
if (totalConnections == 1 && activeConnections == 1 && idleConnections == 0 && pendingConnections == 0 && maxConnections == expectedMaxConnection && maxPendingConnections == expectedMaxPendingAcquire) {
metrics.set(true);
}
if (isSecured) {
double activeStreams = getGaugeValue(CONNECTION_PROVIDER_PREFIX + ACTIVE_STREAMS, "http2." + poolName);
double pendingStreams = getGaugeValue(CONNECTION_PROVIDER_PREFIX + PENDING_STREAMS, "http2." + poolName);
if (activeStreams == 1 && pendingStreams == 0) {
metrics.set(true);
}
}
}).metrics(clientMetricsEnabled, Function.identity()).get().uri("/").responseContent().aggregate().asString().block(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(metrics.get()).isTrue();
if (isSecured) {
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + TOTAL_CONNECTIONS, poolName)).isEqualTo(1);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + IDLE_CONNECTIONS, poolName)).isEqualTo(1);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + ACTIVE_STREAMS, "http2." + poolName)).isEqualTo(0);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + PENDING_STREAMS, "http2." + poolName)).isEqualTo(0);
} else {
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + TOTAL_CONNECTIONS, poolName)).isEqualTo(0);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + IDLE_CONNECTIONS, poolName)).isEqualTo(0);
}
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS, poolName)).isEqualTo(0);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + PENDING_CONNECTIONS, poolName)).isEqualTo(0);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + MAX_CONNECTIONS, poolName)).isEqualTo(expectedMaxConnection);
assertThat(getGaugeValue(CONNECTION_PROVIDER_PREFIX + MAX_PENDING_CONNECTIONS, poolName)).isEqualTo(expectedMaxPendingAcquire);
}
Aggregations