AgentContainerLimitSystemConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { int total = targetVM.getRunningTasks().size() + targetVM.getTasksCurrentlyAssigned().size(); int max = Math.max(1, configuration.getMaxTasksPerMachine()); return total < max ? VALID : TOO_MANY_CONTAINERS; } @Inject  AgentContainerLimitSystemConstraint(SchedulerConfiguration configuration); @Override String getName(); @Override Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState); static boolean isAgentContainerLimitSystemConstraint(String reason); static final String NAME; }
@Test public void testAtLeastOneContainerCanBeScheduled() { when(schedulerConfiguration.getMaxLaunchingTasksPerMachine()).thenReturn(0); ConstraintEvaluator.Result result = constraint.evaluate( createTaskRequest(TASK_ID), createVirtualMachineCurrentStateMock(INSTANCE_ID, Collections.emptyList(), Collections.emptyList()), taskTrackerState); assertThat(result.isSuccessful()).isTrue(); }
@Test public void testContainerLimit() { when(schedulerConfiguration.getMaxLaunchingTasksPerMachine()).thenReturn(2); ConstraintEvaluator.Result result = constraint.evaluate( createTaskRequest(TASK_ID), createVirtualMachineCurrentStateMock(INSTANCE_ID, Collections.emptyList(), createMockAssignmentResultList(2)), taskTrackerState); assertThat(result.isSuccessful()).isFalse(); }