sumanpal97 commented on code in PR #23168:
URL: https://github.com/apache/kafka/pull/23168#discussion_r4347376107


##########
raft/src/test/java/org/apache/kafka/raft/FollowerStateTest.java:
##########
@@ -122,6 +122,24 @@ public void 
testPreVoteAfterSuccessfulFetchFromLeader(boolean isLogUpToDate) {
         assertFalse(state.canGrantVote(ReplicaKey.of(10, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, false));
     }
 
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    public void testPreVoteAfterLeaderResigned(boolean isLogUpToDate) {
+        FollowerState state = newFollowerState(Set.of(1, 2, 3));
+        state.resetFetchTimeoutForSuccessfulFetch(time.milliseconds());
+        state.setLeaderHasResigned();
+
+        assertEquals(isLogUpToDate, state.canGrantVote(ReplicaKey.of(1, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, true));
+        assertEquals(isLogUpToDate, state.canGrantVote(ReplicaKey.of(2, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, true));
+        assertEquals(isLogUpToDate, state.canGrantVote(ReplicaKey.of(3, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, true));
+        assertEquals(isLogUpToDate, state.canGrantVote(ReplicaKey.of(10, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, true));
+
+        assertFalse(state.canGrantVote(ReplicaKey.of(1, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, false));
+        assertFalse(state.canGrantVote(ReplicaKey.of(2, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, false));
+        assertFalse(state.canGrantVote(ReplicaKey.of(3, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, false));
+        assertFalse(state.canGrantVote(ReplicaKey.of(10, 
ReplicaKey.NO_DIRECTORY_ID), isLogUpToDate, false));
+    }

Review Comment:
   Agreed. I added testFollowerGrantsPreVoteAfterLeaderResigns to 
KafkaRaftClientPreVoteTest. After a successful fetch, the follower rejects a 
PreVote from an up-to-date node. It then receives an EndQuorumEpochRequest from 
the leader and grants the same PreVote. I kept the FollowerStateTest case as a 
state-level check, since Mickael asked for it. Happy to drop it if you'd prefer.
   
   



##########
raft/src/test/java/org/apache/kafka/raft/RaftEventSimulationTest.java:
##########
@@ -195,6 +197,83 @@ void canElectNewLeaderAfterOldLeaderFailure() {
         });
     }
 
+    @ParameterizedTest
+    @ValueSource(ints = {4, 5, 6, 7, 8, 9})

Review Comment:
   Makes sense, thanks. I removed the simulation test and replaced it with a 
unit test in KafkaRaftClientPreVoteTest.



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

Reply via email to