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


##########
raft/src/test/java/org/apache/kafka/raft/RaftEventSimulationTest.java:
##########
@@ -305,7 +305,66 @@ void leadershipWillNotChangeIfMajorityIsReachable(
         Cluster cluster = new Cluster(numVoters, numObservers, random);
         MessageRouter router = new MessageRouter(cluster);
         EventScheduler scheduler = schedulerWithDefaultInvariants(cluster);
-        scheduler.addInvariant(new 
StableLeadershipWhenMajorityReachable(cluster));
+        scheduler.addInvariant(new StableLeadership(cluster));
+
+        // Create network partition which would result in ping-pong of 
leadership between nodes 2 and 3 without PreVote
+        // Scenario explained in detail in KIP-996
+        // 0   1
+        // |   |
+        // 2 - 3
+        //  \ /
+        //   4
+        router.filter(
+            0,
+            new DropOutboundRequestsTo(cluster.endpointsFromIds(Set.of(1, 3, 
4)))
+        );
+        router.filter(
+            1,
+            new DropOutboundRequestsTo(cluster.endpointsFromIds(Set.of(0, 2, 
4)))
+        );
+        router.filter(2, new 
DropOutboundRequestsTo(cluster.endpointsFromIds(Set.of(1))));
+        router.filter(3, new 
DropOutboundRequestsTo(cluster.endpointsFromIds(Set.of(0))));
+        router.filter(4, new 
DropOutboundRequestsTo(cluster.endpointsFromIds(Set.of(0, 1))));
+
+        // Start cluster
+        cluster.startAll();
+        schedulePolling(scheduler, cluster, 3, 5);
+        scheduler.schedule(router::deliverAll, 0, 2, 1);
+        scheduler.schedule(new SequentialAppendAction(cluster), 0, 2, 1);
+        scheduler.runUntil(cluster::hasConsistentLeader);
+
+        // Wait for majority to process some data
+        int leaderId = cluster.latestLeader().getAsInt();
+        Set<Integer> majorityQuorum = new HashSet<>(Set.of(0, 1, 2, 3, 4));

Review Comment:
   This feels like it needs a comment explaining what and why.



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