use of reactor.netty.internal.shaded.reactor.pool.PoolConfig in project reactor-netty by reactor.
the class Http2PoolTest method maxLifeTimeMaxConnectionsReached.
@Test
void maxLifeTimeMaxConnectionsReached() 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 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();
Thread.sleep(10);
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(1);
assertThat(http2Pool.connections.size()).isEqualTo(1);
http2Pool.acquire(Duration.ofMillis(10)).as(StepVerifier::create).expectError(PoolAcquireTimeoutException.class).verify(Duration.ofSeconds(1));
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);
} 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 acquireInvalidate.
@Test
void acquireInvalidate() {
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.invalidate().block(Duration.ofSeconds(1));
}
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(0);
for (PooledRef<Connection> slot : acquired) {
// second invalidate() should be ignored and ACQUIRED size should remain the same
slot.invalidate().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 maxLifeTimeMaxConnectionsNotReached.
@Test
void maxLifeTimeMaxConnectionsNotReached() 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, 2);
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);
PooledRef<Connection> acquired2 = http2Pool.acquire().block();
assertThat(acquired2).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(2);
assertThat(http2Pool.connections.size()).isEqualTo(2);
connection2 = acquired2.poolable();
ChannelId id2 = connection2.channel().id();
assertThat(id1).isNotEqualTo(id2);
acquired1.invalidate().block();
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 evictClosedConnectionMaxConnectionsReached.
@Test
void evictClosedConnectionMaxConnectionsReached() 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();
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);
http2Pool.acquire(Duration.ofMillis(10)).as(StepVerifier::create).expectError(PoolAcquireTimeoutException.class).verify(Duration.ofSeconds(1));
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);
} 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 evictClosedConnectionMaxConnectionsNotReached.
@Test
void evictClosedConnectionMaxConnectionsNotReached() 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, 2);
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);
PooledRef<Connection> acquired2 = http2Pool.acquire().block();
assertThat(acquired2).isNotNull();
assertThat(http2Pool.metrics().acquiredSize()).isEqualTo(2);
assertThat(http2Pool.connections.size()).isEqualTo(2);
connection = acquired2.poolable();
ChannelId id2 = connection.channel().id();
assertThat(id1).isNotEqualTo(id2);
acquired1.invalidate().block();
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();
}
}
}
Aggregations