Search in sources :

Example 1 with PooledRef

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();
    }
}
Also used : Connection(reactor.netty.Connection) ArrayList(java.util.ArrayList) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) PoolConfig(reactor.netty.internal.shaded.reactor.pool.PoolConfig) PooledRef(reactor.netty.internal.shaded.reactor.pool.PooledRef) Test(org.junit.jupiter.api.Test)

Example 2 with PooledRef

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();
    }
}
Also used : Connection(reactor.netty.Connection) ArrayList(java.util.ArrayList) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerAdapter(io.netty.channel.ChannelHandlerAdapter) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) PoolConfig(reactor.netty.internal.shaded.reactor.pool.PoolConfig) PooledRef(reactor.netty.internal.shaded.reactor.pool.PooledRef) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Http2MultiplexHandler (io.netty.handler.codec.http2.Http2MultiplexHandler)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 Connection (reactor.netty.Connection)2 PoolConfig (reactor.netty.internal.shaded.reactor.pool.PoolConfig)2 PooledRef (reactor.netty.internal.shaded.reactor.pool.PooledRef)2