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

Code before:
        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();
        assertSame(sameChannel, channel);

        sc.close().syncUninterruptibly();
        sameChannel.close().syncUninterruptibly();
        channel.close().syncUninterruptibly();
        pool.close();
    }

    @ParameterizedTest
    @ValueSource(booleans = { true, false })
    public void testChannelProcessingOrder(boolean orderingType) {
        Tuple t = bootstrap();

        // Start server
        Channel sc = t.sb.bind(t.address).syncUninterruptibly().channel();

        FixedChannelPool pool = new FixedChannelPool(t.cb, new TestChannelPoolHandler(),
                ChannelHealthChecker.ACTIVE, AcquireTimeoutAction.NEW, 500, 1,
                Integer.MAX_VALUE, false, orderingType);

        // create
        int totalChannels = 5;
        List<Channel> channels = new ArrayList<>();
        for (int i = 0; i < totalChannels; i++) {
            Channel channel = pool.acquire().syncUninterruptibly().getNow();
            channels.add(channel);
        }
        for (int i = 0; i < totalChannels; i++) {
            pool.release(channels.get(i)).syncUninterruptibly().getNow();
        }

        // test logic
        for (int i = 0; i < totalChannels; i++) {
            Channel channel = pool.acquire().syncUninterruptibly().getNow();
            if (orderingType) {
                assertSame(channel, channels.get(totalChannels - 1 - i));

Review comment (suggestion):
We could call this "lastInFirstOutOrdering" instead, as "orderingType" is too vague IMO

Code after:
        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();
        assertSame(sameChannel, channel);

        sc.close().syncUninterruptibly();
        sameChannel.close().syncUninterruptibly();
        channel.close().syncUninterruptibly();
        pool.close();
    }

    @ParameterizedTest
    @ValueSource(booleans = { true, false })
    public void testChannelProcessingOrder(boolean lastInFirstOutOrdering) {
        Tuple t = bootstrap();

        // Start server
        Channel sc = t.sb.bind(t.address).syncUninterruptibly().channel();

        FixedChannelPool pool = new FixedChannelPool(t.cb, new TestChannelPoolHandler(),
                ChannelHealthChecker.ACTIVE, AcquireTimeoutAction.NEW, 500, 1,
                Integer.MAX_VALUE, false, lastInFirstOutOrdering);

        // create
        int totalChannels = 5;
        List<Channel> channels = new ArrayList<>();
        for (int i = 0; i < totalChannels; i++) {
            Channel channel = pool.acquire().syncUninterruptibly().getNow();
            channels.add(channel);
        }
        for (int i = 0; i < totalChannels; i++) {
            pool.release(channels.get(i)).syncUninterruptibly().getNow();
        }

        // test logic
        for (int i = 0; i < totalChannels; i++) {
            Channel channel = pool.acquire().syncUninterruptibly().getNow();
            if (lastInFirstOutOrdering) {
                assertSame(channel, channels.get(totalChannels - 1 - i));