junrao commented on code in PR #20200: URL: https://github.com/apache/kafka/pull/20200#discussion_r2217519808
########## metadata/src/test/java/org/apache/kafka/controller/PartitionChangeBuilderTest.java: ########## @@ -1233,4 +1233,72 @@ public void testEligibleLeaderReplicas_ElectLastKnownLeaderShouldFail() { // No change to the partition. assertEquals(Optional.empty(), builder.build()); } + + @Test + public void testEligibleLeaderReplicas_NotEligibleLastKnownLeader() { + short version = 2; + PartitionRegistration partition = new PartitionRegistration.Builder() + .setReplicas(new int[] {1, 2, 3, 4}) + .setDirectories(new Uuid[]{ + Uuid.fromString("zANDdMukTEqefOvHpmniMg"), + Uuid.fromString("Ui2Eq8rbRiuW7m7uiPTRyg"), + Uuid.fromString("MhgJOZrrTsKNcGM0XKK4aA"), + Uuid.fromString("Y25PaCAmRfyGIKxAThhBAw") + }) + .setIsr(new int[] {}) + .setElr(new int[] {}) + .setLastKnownElr(new int[] {1}) + .setLeader(-1) + .setLeaderRecoveryState(LeaderRecoveryState.RECOVERED) + .setLeaderEpoch(100) + .setPartitionEpoch(200) + .build(); + Uuid topicId = Uuid.fromString("FbrrdcfiR-KC2CPSTHaJrg"); + + PartitionChangeBuilder builder = new PartitionChangeBuilder(partition, topicId, 0, r -> false, + metadataVersionForPartitionChangeRecordVersion(version), 3) + .setElection(Election.PREFERRED) + .setEligibleLeaderReplicasEnabled(true) + .setDefaultDirProvider(DEFAULT_DIR_PROVIDER) + .setUseLastKnownLeaderInBalancedRecovery(true); + + builder.setTargetIsr(List.of()); + + // No change to the partition. + assertEquals(Optional.empty(), builder.build()); + } + + @Test + public void testUncleanLeaderElectionFailureIfNoAvailableReplica() { + short version = 2; + PartitionRegistration partition = new PartitionRegistration.Builder() + .setReplicas(new int[] {1, 2, 3, 4}) + .setDirectories(new Uuid[]{ + Uuid.fromString("zANDdMukTEqefOvHpmniMg"), + Uuid.fromString("Ui2Eq8rbRiuW7m7uiPTRyg"), + Uuid.fromString("MhgJOZrrTsKNcGM0XKK4aA"), + Uuid.fromString("Y25PaCAmRfyGIKxAThhBAw") + }) + .setIsr(new int[] {}) + .setElr(new int[] {}) + .setLastKnownElr(new int[] {1}) + .setLeader(-1) + .setLeaderRecoveryState(LeaderRecoveryState.RECOVERED) + .setLeaderEpoch(100) + .setPartitionEpoch(200) + .build(); + Uuid topicId = Uuid.fromString("FbrrdcfiR-KC2CPSTHaJrg"); + + PartitionChangeBuilder builder = new PartitionChangeBuilder(partition, topicId, 0, r -> false, + metadataVersionForPartitionChangeRecordVersion(version), 3) + .setElection(Election.UNCLEAN) Review Comment: The two new tests are identical except for the election method. Could we make a parameterized test that covers both? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org