ahuang98 commented on code in PR #18240:
URL: https://github.com/apache/kafka/pull/18240#discussion_r1917434854


##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientPreVoteTest.java:
##########
@@ -573,4 +700,450 @@ public void testRejectPreVoteIfRemoteLogIsNotUpToDate() 
throws Exception {
         assertTrue(context.client.quorum().isUnattached());
         context.assertSentVoteResponse(Errors.NONE, epoch, 
OptionalInt.empty(), false);
     }
+
+    @ParameterizedTest
+    @EnumSource(value = KRaftVersion.class)
+    public void testPreVoteResponseIgnoredAfterBecomingFollower(KRaftVersion 
kraftVersion) throws Exception {
+        int localId = randomReplicaId();
+        ReplicaKey local = replicaKey(localId, true);
+        ReplicaKey voter2 = replicaKey(localId + 1, true);
+        ReplicaKey voter3 = replicaKey(localId + 2, true);
+        int epoch = 5;
+
+        RaftClientTestContext context = new RaftClientTestContext.Builder(
+            local,
+            VoterSetTest.voterSet(Stream.of(local, voter2, voter3)),
+            kraftVersion
+        )
+            .withUnknownLeader(epoch)
+            .withRaftProtocol(KIP_996_PROTOCOL)
+            .build();
+
+        context.assertUnknownLeaderAndNoVotedCandidate(epoch);
+
+        // Sleep a little to ensure transition to prospective
+        context.time.sleep(context.electionTimeoutMs() * 2L);
+
+        // Wait until the vote requests are inflight
+        context.pollUntilRequest();
+        assertTrue(context.client.quorum().isProspective());
+        List<RaftRequest.Outbound> voteRequests = 
context.collectVoteRequests(epoch, 0, 0);
+        assertEquals(2, voteRequests.size());
+
+        // While the vote requests are still inflight, replica receives a 
BeginEpoch for the same epoch
+        context.deliverRequest(context.beginEpochRequest(epoch, voter3.id()));
+        context.client.poll();
+        context.assertElectedLeader(epoch, voter3.id());
+
+        // If PreVote responses are received now they should be ignored
+        VoteResponseData voteResponse1 = context.voteResponse(true, 
OptionalInt.empty(), epoch);

Review Comment:
   yes, it was just for variation (since both could be valid responses)



-- 
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

Reply via email to