@Test
public void testAcquire() throws Exception {

    EventLoopGroup group = new LocalEventLoopGroup();
    LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
    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();
    ChannelPool pool = new SimpleChannelPool(cb, handler);
    Channel channel = pool.acquire().sync().getNow();
    pool.release(channel).syncUninterruptibly();
    Channel channel2 = pool.acquire().sync().getNow();
    assertSame(channel, channel2);
    assertEquals(1, handler.channelCount());
    pool.release(channel2).syncUninterruptibly();
    // Should fail on multiple release calls.
    try {
        pool.release(channel2).syncUninterruptibly();
        fail();
    } catch (IllegalArgumentException e) {
        // expected
        assertFalse(channel.isActive());
    }
    assertEquals(1, handler.acquiredCount());
    assertEquals(2, handler.releasedCount());
    sc.close().sync();
    group.shutdownGracefully();
}