use of com.linkedin.kafka.cruisecontrol.executor.strategy.PrioritizeSmallReplicaMovementStrategy in project cruise-control by linkedin.
the class ExecutionTaskPlannerTest method testDynamicConfigReplicaMovementStrategy.
@Test
public void testDynamicConfigReplicaMovementStrategy() {
List<ExecutionProposal> proposals = new ArrayList<>();
proposals.add(_partitionMovement0);
proposals.add(_partitionMovement1);
proposals.add(_partitionMovement2);
proposals.add(_partitionMovement3);
ExecutionTaskPlanner planner = new ExecutionTaskPlanner(null, new KafkaCruiseControlConfig(KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties()));
Set<PartitionInfo> partitions = new HashSet<>();
partitions.add(generatePartitionInfo(_partitionMovement0, true));
partitions.add(generatePartitionInfo(_partitionMovement1, false));
partitions.add(generatePartitionInfo(_partitionMovement2, true));
partitions.add(generatePartitionInfo(_partitionMovement3, false));
Cluster expectedCluster = new Cluster(null, _expectedNodes, partitions, Collections.emptySet(), Collections.emptySet());
StrategyOptions strategyOptions = new StrategyOptions.Builder(expectedCluster).build();
Map<Integer, Integer> readyBrokers = new HashMap<>();
readyBrokers.put(0, 8);
readyBrokers.put(1, 8);
readyBrokers.put(2, 8);
readyBrokers.put(3, 8);
planner.addExecutionProposals(proposals, strategyOptions, null);
List<ExecutionTask> partitionMovementTasks = planner.getInterBrokerReplicaMovementTasks(readyBrokers, Collections.emptySet(), _defaultPartitionsMaxCap);
assertEquals("First task", _partitionMovement0, partitionMovementTasks.get(0).proposal());
assertEquals("Second task", _partitionMovement2, partitionMovementTasks.get(1).proposal());
assertEquals("Third task", _partitionMovement1, partitionMovementTasks.get(2).proposal());
planner.addExecutionProposals(proposals, strategyOptions, new PostponeUrpReplicaMovementStrategy());
partitionMovementTasks = planner.getInterBrokerReplicaMovementTasks(readyBrokers, Collections.emptySet(), _defaultPartitionsMaxCap);
assertEquals("First task", _partitionMovement1, partitionMovementTasks.get(0).proposal());
assertEquals("Second task", _partitionMovement3, partitionMovementTasks.get(1).proposal());
assertEquals("Third task", _partitionMovement0, partitionMovementTasks.get(2).proposal());
planner.addExecutionProposals(proposals, strategyOptions, new PrioritizeLargeReplicaMovementStrategy());
partitionMovementTasks = planner.getInterBrokerReplicaMovementTasks(readyBrokers, Collections.emptySet(), _defaultPartitionsMaxCap);
assertEquals("First task", _partitionMovement1, partitionMovementTasks.get(0).proposal());
assertEquals("Second task", _partitionMovement3, partitionMovementTasks.get(1).proposal());
assertEquals("Third task", _partitionMovement2, partitionMovementTasks.get(2).proposal());
planner.addExecutionProposals(proposals, strategyOptions, new PrioritizeSmallReplicaMovementStrategy());
partitionMovementTasks = planner.getInterBrokerReplicaMovementTasks(readyBrokers, Collections.emptySet(), _defaultPartitionsMaxCap);
assertEquals("First task", _partitionMovement0, partitionMovementTasks.get(0).proposal());
assertEquals("Second task", _partitionMovement2, partitionMovementTasks.get(1).proposal());
assertEquals("Third task", _partitionMovement3, partitionMovementTasks.get(2).proposal());
assertEquals("Fourth task", _partitionMovement1, partitionMovementTasks.get(3).proposal());
}
Aggregations