@ParameterizedTest
    @ValueSource(booleans = {true, false})
    public void testEligibleLeaderReplicas_IsrCanShrinkToZero(boolean lastKnownLeaderEnabled) {
        short version = 2;
        PartitionRegistration partition = new PartitionRegistration.Builder()
            .setReplicas(new int[] {1, 2, 3, 4})
            .setDirectories(new Uuid[]{
                    Uuid.fromString("MrTKKPEpRv66ZpWv4V7EBQ"),
                    Uuid.fromString("CkvgdEcWTVmdhfNuJXL0xA"),
                    Uuid.fromString("4a2coMsPRkSCsiTVWSksSw"),
                    Uuid.fromString("tmPdVjzASZ2ZqiS0cVJvtQ")
            })
            .setIsr(new int[] {1, 2, 3, 4})
            .setElr(new int[] {})
            .setLastKnownElr(new int[] {})
            .setLeader(1)
            .setLeaderRecoveryState(LeaderRecoveryState.RECOVERED)
            .setLeaderEpoch(100)
            .setPartitionEpoch(200)
            .build();
        Uuid topicId = Uuid.fromString("FbrrdcfiR-KC2CPSTHaJrg");

        // Mark all the replicas offline.
        PartitionChangeBuilder builder = new PartitionChangeBuilder(partition, topicId, 0, r -> false,
                metadataVersionForPartitionChangeRecordVersion(version), 3)
            .setElection(Election.PREFERRED)
            .setEligibleLeaderReplicasEnabled(true)
            .setDefaultDirProvider(DEFAULT_DIR_PROVIDER)
            .setUseLastKnownLeaderInBalancedRecovery(lastKnownLeaderEnabled);

        builder.setTargetIsr(Collections.emptyList());

        PartitionChangeRecord record = new PartitionChangeRecord()
            .setTopicId(topicId)
            .setPartitionId(0)
            .setIsr(Collections.emptyList())
            .setLeader(-1)
            .setLeaderRecoveryState(LeaderRecoveryState.NO_CHANGE)
            .setEligibleLeaderReplicas(Arrays.asList(1, 2, 3, 4));

        if (lastKnownLeaderEnabled) {
            record.setLastKnownElr(Collections.singletonList(1));
        }

        ApiMessageAndVersion expectedRecord = new ApiMessageAndVersion(record, version);
        assertEquals(Optional.of(expectedRecord), builder.build());
        partition = partition.merge((PartitionChangeRecord) builder.build().get().message());
        assertArrayEquals(new int[]{1, 2, 3, 4}, partition.elr, partition.toString());
        if (lastKnownLeaderEnabled) {
            assertArrayEquals(new int[]{1}, partition.lastKnownElr, partition.toString());
            builder = new PartitionChangeBuilder(partition, topicId, 0, r -> false,
                    metadataVersionForPartitionChangeRecordVersion(version), 3)
                .setElection(Election.PREFERRED)
                .setEligibleLeaderReplicasEnabled(true)
                .setUncleanShutdownReplicas(Collections.singletonList(2))
                .setDefaultDirProvider(DEFAULT_DIR_PROVIDER)
                .setUseLastKnownLeaderInBalancedRecovery(lastKnownLeaderEnabled);
            PartitionChangeRecord changeRecord = (PartitionChangeRecord) builder.build().get().message();
            assertNull(changeRecord.lastKnownElr(), changeRecord.toString());
        } else {
            assertArrayEquals(new int[]{}, partition.lastKnownElr, partition.toString());
        }
        assertArrayEquals(new int[]{}, partition.isr, partition.toString());
    }
Regression test for KAFKA-16624. Tests that when targetIsr is the empty list, but we
cannot actually change the ISR, triggerLeaderEpochBumpForIsrShrinkIfNeeded does not engage.
metadata/src/test/java/org/apache/kafka/controller/PartitionChangeBuilderTest.java