use of reactor.netty.internal.shaded.reactor.pool.PoolConfig in project reactor-netty by reactor.
the class Http2PoolTest method evictClosedConnection.
@Test
void evictClosedConnection() throws Exception {
PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder = PoolBuilder.from(Mono.fromSupplier(() -> {
Channel channel = new EmbeddedChannel(new TestChannelId(), Http2FrameCodecBuilder.forClient().build());
return Connection.from(channel);
})).idleResourceReuseLruOrder().maxPendingAcquireUnbounded().sizeBetween(0, 1);
Http2Pool http2Pool = poolBuilder.build(config -> new Http2Pool(config, -1));
Connection connection = null;
try {
PooledRef<Connection> acquired1 = http2Pool.acquire().block();
assertThat(acquired1).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
connection = acquired1.poolable();
ChannelId id1 = connection.channel().id();
CountDownLatch latch = new CountDownLatch(1);
((EmbeddedChannel) connection.channel()).finishAndReleaseAll();
connection.onDispose(latch::countDown);
connection.dispose();
assertThat(latch.await(1, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
acquired1.invalidate().block();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
assertThat(http2Pool.connections.size()).isEqualTo(0);
PooledRef<Connection> acquired2 = http2Pool.acquire().block();
assertThat(acquired2).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
connection = acquired2.poolable();
ChannelId id2 = connection.channel().id();
assertThat(id1).isNotEqualTo(id2);
acquired2.invalidate().block();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
assertThat(http2Pool.connections.size()).isEqualTo(0);
} finally {
if (connection != null) {
((EmbeddedChannel) connection.channel()).finishAndReleaseAll();
connection.dispose();
}
}
}
use of reactor.netty.internal.shaded.reactor.pool.PoolConfig in project reactor-netty by reactor.
the class Http2PoolTest method acquireRelease.
@Test
void acquireRelease() {
EmbeddedChannel channel = new EmbeddedChannel(Http2FrameCodecBuilder.forClient().build(), new Http2MultiplexHandler(new ChannelHandlerAdapter() {
}));
PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder = PoolBuilder.from(Mono.just(Connection.from(channel))).idleResourceReuseLruOrder().maxPendingAcquireUnbounded().sizeBetween(0, 1);
InstrumentedPool<Connection> http2Pool = poolBuilder.build(config -> new Http2Pool(config, -1));
try {
List<PooledRef<Connection>> acquired = new ArrayList<>();
http2Pool.acquire().subscribe(acquired::add);
http2Pool.acquire().subscribe(acquired::add);
http2Pool.acquire().subscribe(acquired::add);
assertThat(acquired).hasSize(3);
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(3);
for (PooledRef<Connection> slot : acquired) {
slot.release().block(Duration.ofSeconds(1));
}
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
for (PooledRef<Connection> slot : acquired) {
// second release() should be ignored and ACQUIRED size should remain the same
slot.release().block(Duration.ofSeconds(1));
}
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
} finally {
channel.finishAndReleaseAll();
Connection.from(channel).dispose();
}
}
use of reactor.netty.internal.shaded.reactor.pool.PoolConfig in project reactor-netty by reactor.
the class Http2PoolTest method maxLifeTime.
@Test
void maxLifeTime() throws Exception {
PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder = PoolBuilder.from(Mono.fromSupplier(() -> {
Channel channel = new EmbeddedChannel(new TestChannelId(), Http2FrameCodecBuilder.forClient().build());
return Connection.from(channel);
})).idleResourceReuseLruOrder().maxPendingAcquireUnbounded().sizeBetween(0, 1);
Http2Pool http2Pool = poolBuilder.build(config -> new Http2Pool(config, 10));
Connection connection1 = null;
Connection connection2 = null;
try {
PooledRef<Connection> acquired1 = http2Pool.acquire().block();
assertThat(acquired1).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
connection1 = acquired1.poolable();
ChannelId id1 = connection1.channel().id();
Thread.sleep(10);
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
acquired1.invalidate().block();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
assertThat(http2Pool.connections.size()).isEqualTo(0);
PooledRef<Connection> acquired2 = http2Pool.acquire().block();
assertThat(acquired2).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
connection2 = acquired2.poolable();
ChannelId id2 = connection2.channel().id();
assertThat(id1).isNotEqualTo(id2);
acquired2.invalidate().block();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
assertThat(http2Pool.connections.size()).isEqualTo(0);
} finally {
if (connection1 != null) {
((EmbeddedChannel) connection1.channel()).finishAndReleaseAll();
connection1.dispose();
}
if (connection2 != null) {
((EmbeddedChannel) connection2.channel()).finishAndReleaseAll();
connection2.dispose();
}
}
}
use of reactor.netty.internal.shaded.reactor.pool.PoolConfig in project reactor-netty by reactor.
the class Http2PoolTest method nonHttp2ConnectionEmittedOnce.
@Test
void nonHttp2ConnectionEmittedOnce() {
EmbeddedChannel channel = new EmbeddedChannel();
PoolBuilder<Connection, PoolConfig<Connection>> poolBuilder = PoolBuilder.from(Mono.just(Connection.from(channel))).idleResourceReuseLruOrder().maxPendingAcquireUnbounded().sizeBetween(0, 1);
InstrumentedPool<Connection> http2Pool = poolBuilder.build(config -> new Http2Pool(config, -1));
try {
PooledRef<Connection> acquired = http2Pool.acquire().block(Duration.ofSeconds(1));
assertThat(acquired).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
http2Pool.acquire(Duration.ofMillis(10)).as(StepVerifier::create).expectError(PoolAcquireTimeoutException.class).verify(Duration.ofSeconds(1));
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
acquired.invalidate().block(Duration.ofSeconds(1));
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
} finally {
channel.finishAndReleaseAll();
Connection.from(channel).dispose();
}
}
Aggregations