jsancio commented on code in PR #15397: URL: https://github.com/apache/kafka/pull/15397#discussion_r1496389863
########## raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientTest.java: ########## @@ -2958,6 +2958,59 @@ public void testHandleCommitCallbackFiresInCandidateState() throws Exception { assertEquals(OptionalInt.empty(), secondListener.currentClaimedEpoch()); } + @Test + public void testHandleLeaderChangeFiresAfterUnattachedRegistration() throws Exception { + int localId = 0; + int otherNodeId = 1; + int epoch = 7; + Set<Integer> voters = Utils.mkSet(localId, otherNodeId); + + RaftClientTestContext context = new RaftClientTestContext.Builder(localId, voters) + .withUnknownLeader(epoch) + .build(); + + // Register another listener and verify that it is notified of latest epoch + RaftClientTestContext.MockListener secondListener = new RaftClientTestContext.MockListener( + OptionalInt.of(localId) + ); + context.client.register(secondListener); + context.client.poll(); + + // Expected leader change notification + LeaderAndEpoch expectedLeaderAndEpoch = new LeaderAndEpoch(OptionalInt.empty(), epoch); + assertEquals(expectedLeaderAndEpoch, secondListener.currentLeaderAndEpoch()); + + // Transition to follower and observer leader change + context.deliverRequest(context.beginEpochRequest(epoch, otherNodeId)); + context.pollUntilResponse(); + + // Expected leader change notification + expectedLeaderAndEpoch = new LeaderAndEpoch(OptionalInt.of(otherNodeId), epoch); + assertEquals(expectedLeaderAndEpoch, secondListener.currentLeaderAndEpoch()); + } + + @Test + public void testHandleLeaderChangeFiresAfterFollowerRegistration() throws Exception { + int localId = 0; + int otherNodeId = 1; + int epoch = 7; + Set<Integer> voters = Utils.mkSet(localId, otherNodeId); + + RaftClientTestContext context = new RaftClientTestContext.Builder(localId, voters) + .withElectedLeader(epoch, otherNodeId) + .build(); + + // Register another listener and verify that it is notified of latest epoch + RaftClientTestContext.MockListener secondListener = new RaftClientTestContext.MockListener( + OptionalInt.of(localId) + ); + context.client.register(secondListener); + context.client.poll(); + + LeaderAndEpoch expectedLeaderAndEpoch = new LeaderAndEpoch(OptionalInt.of(otherNodeId), epoch); + assertEquals(expectedLeaderAndEpoch, secondListener.currentLeaderAndEpoch()); + } Review Comment: Both of these tests fail against trunk. -- 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