Search in sources :

Example 1 with PreferredLeaderElectionGoal

use of com.linkedin.kafka.cruisecontrol.analyzer.goals.PreferredLeaderElectionGoal in project cruise-control by linkedin.

the class PreferredLeaderElectionGoalTest method testOptimize.

@Test
public void testOptimize() throws KafkaCruiseControlException {
    ClusterModel clusterModel = createClusterModel();
    PreferredLeaderElectionGoal goal = new PreferredLeaderElectionGoal();
    goal.optimize(clusterModel, Collections.emptySet(), Collections.emptySet());
    for (String t : Arrays.asList(TOPIC0, TOPIC1, TOPIC2)) {
        for (int p = 0; p < 3; p++) {
            List<Replica> replicas = clusterModel.partition(new TopicPartition(t, p)).replicas();
            for (int i = 0; i < 3; i++) {
                // only the first replica should be leader.
                assertEquals(i == 0, replicas.get(i).isLeader());
            }
        }
    }
}
Also used : ClusterModel(com.linkedin.kafka.cruisecontrol.model.ClusterModel) PreferredLeaderElectionGoal(com.linkedin.kafka.cruisecontrol.analyzer.goals.PreferredLeaderElectionGoal) TopicPartition(org.apache.kafka.common.TopicPartition) Replica(com.linkedin.kafka.cruisecontrol.model.Replica) Test(org.junit.Test)

Aggregations

PreferredLeaderElectionGoal (com.linkedin.kafka.cruisecontrol.analyzer.goals.PreferredLeaderElectionGoal)1 ClusterModel (com.linkedin.kafka.cruisecontrol.model.ClusterModel)1 Replica (com.linkedin.kafka.cruisecontrol.model.Replica)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 Test (org.junit.Test)1