Home / Function/ testBoundedChannelPoolSegment() — netty Function Reference

testBoundedChannelPoolSegment() — netty Function Reference

Architecture documentation for the testBoundedChannelPoolSegment() function in SimpleChannelPoolTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  987af820_7f06_6372_53f6_60207baf0284["testBoundedChannelPoolSegment()"]
  dfb428cc_ecc3_d271_5689_7e428381a986["SimpleChannelPoolTest"]
  987af820_7f06_6372_53f6_60207baf0284 -->|defined in| dfb428cc_ecc3_d271_5689_7e428381a986
  style 987af820_7f06_6372_53f6_60207baf0284 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/pool/SimpleChannelPoolTest.java lines 98–155

    @Test
    public void testBoundedChannelPoolSegment() throws Exception {
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory());
        LocalAddress addr = new LocalAddress(getLocalAddrId());
        Bootstrap cb = new Bootstrap();
        cb.remoteAddress(addr);
        cb.group(group)
          .channel(LocalChannel.class);

        ServerBootstrap sb = new ServerBootstrap();
        sb.group(group)
          .channel(LocalServerChannel.class)
          .childHandler(new ChannelInitializer<LocalChannel>() {
              @Override
              public void initChannel(LocalChannel ch) throws Exception {
                  ch.pipeline().addLast(new ChannelInboundHandlerAdapter());
              }
          });

        // Start server
        Channel sc = sb.bind(addr).sync().channel();
        CountingChannelPoolHandler handler = new CountingChannelPoolHandler();

        final ChannelPool pool = new SimpleChannelPool(cb, handler, ChannelHealthChecker.ACTIVE) {
            private final Queue<Channel> queue = new LinkedBlockingQueue<Channel>(1);

            @Override
            protected Channel pollChannel() {
                return queue.poll();
            }

            @Override
            protected boolean offerChannel(Channel ch) {
                return queue.offer(ch);
            }
        };

        Channel channel = pool.acquire().sync().getNow();
        final Channel channel2 = pool.acquire().sync().getNow();

        pool.release(channel).syncUninterruptibly().getNow();
        assertThrows(IllegalStateException.class, new Executable() {
            @Override
            public void execute() throws Throwable {
                pool.release(channel2).syncUninterruptibly();
            }
        });
        channel2.close().sync();

        assertEquals(2, handler.channelCount());
        assertEquals(2, handler.acquiredCount());
        assertEquals(1, handler.releasedCount());
        sc.close().sync();
        channel.close().sync();
        channel2.close().sync();
        pool.close();
        group.shutdownGracefully();
    }

Domain

Subdomains

Frequently Asked Questions

What does testBoundedChannelPoolSegment() do?
testBoundedChannelPoolSegment() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/pool/SimpleChannelPoolTest.java.
Where is testBoundedChannelPoolSegment() defined?
testBoundedChannelPoolSegment() is defined in transport/src/test/java/io/netty/channel/pool/SimpleChannelPoolTest.java at line 98.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free