use of com.linkedin.kafka.cruisecontrol.model.ReplicaPlacementInfo in project cruise-control by linkedin.
the class PreferredLeaderElectionGoalTest method testOptimizeWithDemotedBrokersAndSkipUrpDemotionAndExcludeFollowerDemotion.
@Test
public void testOptimizeWithDemotedBrokersAndSkipUrpDemotionAndExcludeFollowerDemotion() {
ClusterModelAndInfo clusterModelAndInfo = createClusterModel(false, false);
ClusterModel clusterModel = clusterModelAndInfo.clusterModel();
Cluster cluster = clusterModelAndInfo.clusterInfo();
clusterModel.setBrokerState(0, Broker.State.DEMOTED);
Map<TopicPartition, ReplicaPlacementInfo> originalLeaderDistribution = clusterModel.getLeaderDistribution();
PreferredLeaderElectionGoal goal = new PreferredLeaderElectionGoal(true, true, cluster);
// Before the optimization, goals are expected to be undecided wrt their provision status.
assertEquals(ProvisionStatus.UNDECIDED, goal.provisionResponse().status());
goal.optimize(clusterModel, Collections.emptySet(), new OptimizationOptions(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()));
// After the optimization, PreferredLeaderElectionGoal is expected to be undecided wrt its provision status.
assertEquals(ProvisionStatus.UNDECIDED, goal.provisionResponse().status());
Map<TopicPartition, ReplicaPlacementInfo> optimizedLeaderDistribution = clusterModel.getLeaderDistribution();
Map<TopicPartition, List<ReplicaPlacementInfo>> optimizedReplicaDistribution = clusterModel.getReplicaDistribution();
for (String t : Arrays.asList(TOPIC0, TOPIC1, TOPIC2)) {
for (int p = 0; p < 3; p++) {
TopicPartition tp = new TopicPartition(t, p);
if (originalLeaderDistribution.get(tp).brokerId() == 0 && t.equals(TOPIC0)) {
List<Integer> replicas = optimizedReplicaDistribution.get(tp).stream().mapToInt(ReplicaPlacementInfo::brokerId).boxed().collect(Collectors.toList());
assertEquals("Tp " + tp, 0, replicas.get(replicas.size() - 1).intValue());
} else {
assertEquals("Tp " + tp, originalLeaderDistribution.get(tp), optimizedLeaderDistribution.get(tp));
}
}
}
}
Aggregations