use of reactor.netty.internal.shaded.reactor.pool.InstrumentedPool in project reactor-netty by reactor.
the class DefaultPooledConnectionProviderTest method doTestIssue1982.
private void doTestIssue1982(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable Http2SslContextSpec serverCtx, @Nullable Http2SslContextSpec clientCtx) throws Exception {
HttpServer server = serverCtx != null ? HttpServer.create().secure(sslContextSpec -> sslContextSpec.sslContext(serverCtx)) : HttpServer.create();
disposableServer = server.protocol(serverProtocols).http2Settings(h2 -> h2.maxConcurrentStreams(20)).handle((req, res) -> res.sendString(Mono.just("testIssue1982").delayElement(Duration.ofMillis(100)))).bindNow();
DefaultPooledConnectionProvider provider = (DefaultPooledConnectionProvider) ConnectionProvider.create("", 5);
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger counter = new AtomicInteger();
HttpClient mainClient = clientCtx != null ? HttpClient.create(provider).port(disposableServer.port()).secure(sslContextSpec -> sslContextSpec.sslContext(clientCtx)) : HttpClient.create(provider).port(disposableServer.port());
HttpClient client = mainClient.protocol(clientProtocols).observe((conn, state) -> {
if (state == ConnectionObserver.State.CONNECTED) {
counter.incrementAndGet();
}
if (state == ConnectionObserver.State.RELEASED && counter.decrementAndGet() == 0) {
latch.countDown();
}
});
try {
Flux.range(0, 80).flatMap(i -> client.get().uri("/").responseContent().aggregate().asString()).blockLast(Duration.ofSeconds(10));
assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
@SuppressWarnings({ "unchecked", "rawtypes" }) InstrumentedPool<DefaultPooledConnectionProvider.PooledConnection> channelPool = provider.channelPools.values().toArray(new InstrumentedPool[0])[0];
InstrumentedPool.PoolMetrics metrics = channelPool.metrics();
assertThat(metrics.acquiredSize()).isEqualTo(0);
assertThat(metrics.allocatedSize()).isEqualTo(metrics.idleSize());
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
use of reactor.netty.internal.shaded.reactor.pool.InstrumentedPool in project reactor-netty by reactor.
the class DefaultPooledConnectionProviderTest method testConnectionReturnedToParentPoolWhenNoActiveStreams.
@Test
void testConnectionReturnedToParentPoolWhenNoActiveStreams() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
disposableServer = createServer().wiretap(false).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)).route(routes -> routes.post("/", (req, res) -> res.send(req.receive().retain()))).bindNow();
int requestsNum = 10;
CountDownLatch latch = new CountDownLatch(1);
DefaultPooledConnectionProvider provider = (DefaultPooledConnectionProvider) ConnectionProvider.create("testConnectionReturnedToParentPoolWhenNoActiveStreams", 5);
AtomicInteger counter = new AtomicInteger();
HttpClient client = createClient(provider, disposableServer.port()).wiretap(false).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)).observe((conn, state) -> {
if (state == ConnectionObserver.State.CONNECTED) {
counter.incrementAndGet();
}
if (state == ConnectionObserver.State.RELEASED && counter.decrementAndGet() == 0) {
latch.countDown();
}
});
try {
Flux.range(0, requestsNum).flatMap(i -> client.post().uri("/").send(ByteBufMono.fromString(Mono.just("testConnectionReturnedToParentPoolWhenNoActiveStreams"))).responseContent().aggregate().asString()).blockLast(Duration.ofSeconds(5));
assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(provider.channelPools).hasSize(1);
@SuppressWarnings({ "unchecked", "rawtypes" }) InstrumentedPool<DefaultPooledConnectionProvider.PooledConnection> channelPool = provider.channelPools.values().toArray(new InstrumentedPool[0])[0];
InstrumentedPool.PoolMetrics metrics = channelPool.metrics();
assertThat(metrics.acquiredSize()).isEqualTo(0);
assertThat(metrics.allocatedSize()).isEqualTo(metrics.idleSize());
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
Aggregations