Home / Function/ testAcquire() — netty Function Reference

testAcquire() — netty Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/pool/SimpleChannelPoolTest.java lines 47–96

    @Test
    public void testAcquire() 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);

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

        pool.release(channel).syncUninterruptibly();

        final Channel channel2 = pool.acquire().sync().getNow();
        assertSame(channel, channel2);
        assertEquals(1, handler.channelCount());
        pool.release(channel2).syncUninterruptibly();

        // Should fail on multiple release calls.
        assertThrows(IllegalArgumentException.class, new Executable() {
            @Override
            public void execute() throws Throwable {
                pool.release(channel2).syncUninterruptibly();
            }
        });
        assertFalse(channel.isActive());

        assertEquals(2, handler.acquiredCount());
        assertEquals(2, handler.releasedCount());

        sc.close().sync();
        pool.close();
        group.shutdownGracefully();
    }

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free