hachikuji commented on a change in pull request #9302:
URL: https://github.com/apache/kafka/pull/9302#discussion_r491099373
##########
File path:
core/src/test/scala/unit/kafka/controller/ControllerIntegrationTest.scala
##########
@@ -444,6 +444,29 @@ class ControllerIntegrationTest extends
ZooKeeperTestHarness {
"failed to get expected partition state upon broker startup")
}
+ @Test
+ def testAutoPreferredReplicaLeaderElectionWithReassigningPartitions(): Unit
= {
+ servers = makeServers(2, autoLeaderRebalanceEnable = true)
+ val controllerId = TestUtils.waitUntilControllerElected(zkClient)
+ val otherBrokerId = servers.map(_.config.brokerId).filter(_ !=
controllerId).head
+ val tp = new TopicPartition("t", 0)
+ val assignment = Map(tp.partition -> Seq(1, 0))
+ TestUtils.createTopic(zkClient, tp.topic, partitionReplicaAssignment =
assignment, servers = servers)
+ val reassigningTp = new TopicPartition("reassigning", 0)
+ val reassigningAssignment = Map(reassigningTp.partition -> Seq(0))
+ TestUtils.createTopic(zkClient, reassigningTp.topic,
partitionReplicaAssignment = reassigningAssignment, servers = servers)
+ servers(otherBrokerId).shutdown()
+ servers(otherBrokerId).awaitShutdown()
+ waitForPartitionState(tp, firstControllerEpoch, controllerId,
LeaderAndIsr.initialLeaderEpoch + 1,
+ "failed to get expected partition state upon broker shutdown")
+
+ // Directly edit the controller context to simulate a reassigning partition
+
servers(controllerId).kafkaController.controllerContext.partitionsBeingReassigned.add(reassigningTp)
Review comment:
Feels a bit nasty to dip into the controller context directly. An
alternative way of testing this might be something like this:
1. Start with two partitions
2. Reassign one partition to a new replica with a low throttle
3. Reassign the other partition so that just the preferred leader changes
4. Trigger preferred election and verify that the leader of the second
partition has changed
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]