ahuang98 commented on code in PR #18240:
URL: https://github.com/apache/kafka/pull/18240#discussion_r1917398687
##########
raft/src/test/java/org/apache/kafka/raft/KafkaRaftClientPreVoteTest.java:
##########
@@ -86,186 +99,249 @@ public void
testHandlePreVoteRequestAsFollowerWithElectedLeader(boolean hasFetch
assertTrue(context.client.quorum().isUnattachedNotVoted());
}
- @Test
- public void testHandlePreVoteRequestAsCandidate() throws Exception {
+ @ParameterizedTest
+ @EnumSource(value = KRaftVersion.class)
+ public void
testHandlePreVoteRequestAsFollowerWithVotedCandidate(KRaftVersion kraftVersion)
throws Exception {
+ int localId = randomReplicaId();
+ int epoch = 2;
+ ReplicaKey localKey = replicaKey(localId, true);
+ ReplicaKey otherNodeKey = replicaKey(localId + 1, true);
+ ReplicaKey votedCandidateKey = replicaKey(localId + 2, true);
+ VoterSet voters = VoterSetTest.voterSet(Stream.of(localKey,
otherNodeKey, votedCandidateKey));
+
+ RaftClientTestContext context = new
RaftClientTestContext.Builder(localKey, voters, kraftVersion)
+ .withVotedCandidate(epoch, votedCandidateKey)
+ .withRaftProtocol(KIP_996_PROTOCOL)
+ .build();
+ context.pollUntilRequest();
+ context.assertSentFetchRequest();
+ context.deliverRequest(context.beginEpochRequest(epoch,
votedCandidateKey.id(), voters.listeners(votedCandidateKey.id())));
+ context.pollUntilResponse();
+ context.assertSentBeginQuorumEpochResponse(Errors.NONE);
+ assertTrue(context.client.quorum().isFollower());
+
+ // follower can grant PreVotes if it has not fetched successfully from
leader yet
+ context.deliverRequest(context.preVoteRequest(epoch, otherNodeKey,
epoch, 1));
+ context.pollUntilResponse();
+ context.assertSentVoteResponse(Errors.NONE, epoch,
OptionalInt.of(votedCandidateKey.id()), true);
Review Comment:
yes, I had considered allocating a different node for local to make its
voted candidate, but rationalized that the behavior won't change and that this
is also a valid/common state for a follower to be in
(votedCandidateKey=leaderId)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]