use of reactor.netty.internal.shaded.reactor.pool.PooledRef 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.PooledRef 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();
}
}
Aggregations