Repository: netty/netty
File: transport/src/test/java/io/netty/channel/pool/FixedChannelPoolTest.java (Java)

Code before:
            assertSame(e, exception);
        }

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

    private Tuple bootstrap() {
        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) {
                        ch.pipeline().addLast(new ChannelInboundHandlerAdapter());
                    }
                });

        return new Tuple(addr, cb, sb);
    }

    private static final class TestChannelPoolHandler extends AbstractChannelPoolHandler {
        @Override
        public void channelCreated(Channel ch) throws Exception {
            // NOOP
        }
    }

    private static final class Tuple {

        LocalAddress address;
        Bootstrap cb;
        ServerBootstrap sb;

        Tuple(LocalAddress address, Bootstrap cb, ServerBootstrap sb) {
            this.address = address;
            this.cb = cb;
            this.sb = sb;
        }
    }
}


Review comment (suggestion):
```suggestion
        assertSame(channel, sameChannel);
```

Code after:

        try {
            pool.acquire().sync();
        } catch (NullPointerException e) {
            assertSame(e, exception);
        }

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

    @Test
    public void testChannelReleaseHealthCheck() {
        Tuple t = bootstrap();

        // Start server
        Channel sc = t.sb.bind(t.address).syncUninterruptibly().channel();
        ChannelPoolHandler handler = new TestChannelPoolHandler();
        InnerFixedChannelPool pool = new InnerFixedChannelPool(t.cb, handler, ChannelHealthChecker.ACTIVE,
                AcquireTimeoutAction.NEW, 500, 1, Integer.MAX_VALUE, true);

        // releaseHealthCheck=true,channel=open,doHealthCheckOnRelease
        Channel channel = pool.acquire().syncUninterruptibly().getNow();
        pool.release(channel).syncUninterruptibly().getNow();
        Channel sameChannel = pool.acquire().syncUninterruptibly().getNow();
        assertSame(sameChannel, channel);

        // releaseHealthCheck=true,channel=close,doHealthCheckOnRelease
        sameChannel.close().syncUninterruptibly();
        pool.release(channel).syncUninterruptibly().getNow();
        sameChannel = pool.acquire().syncUninterruptibly().getNow();
        assertNotSame(sameChannel, channel);

        // close all and create a new poll
        sameChannel.close().syncUninterruptibly();
        channel.close().syncUninterruptibly();
        pool.close();
        pool = new InnerFixedChannelPool(t.cb, handler, ChannelHealthChecker.ACTIVE,
                AcquireTimeoutAction.NEW, 500, 1, Integer.MAX_VALUE, false);

        // releaseHealthCheck=false,channel=open,releaseAndOffer
        channel = pool.acquire().syncUninterruptibly().getNow();
        pool.release(channel).syncUninterruptibly().getNow();
        sameChannel = pool.acquire().syncUninterruptibly().getNow();
        assertSame(sameChannel, channel);

        // releaseHealthCheck=false,channel=close,releaseAndOffer
        sameChannel.close().syncUninterruptibly();
        pool.release(channel).syncUninterruptibly().getNow();
        // the acquire will do a heath check.. this is why we call the special method
        sameChannel = pool.pollChannel();