AntiAffinitySchedulingConstraint implements SchedulingConstraint { @Override public boolean testSchedulability(final ExecutorRepresenter executor, final Task task) { for (final Task runningTask : executor.getRunningTasks()) { if (isInAntiAffinityGroup(runningTask) && isInAntiAffinityGroup(task)) { return false; } } return true; } @Inject  AntiAffinitySchedulingConstraint(); @Override boolean testSchedulability(final ExecutorRepresenter executor, final Task task);  }
@Test public void testScheduleSkewedTasks() { final SchedulingConstraint schedulingConstraint = new AntiAffinitySchedulingConstraint(); final HashSet<Integer> antiAffinityGroup = new HashSet<>(Arrays.asList(0, 1)); final ExecutionPropertyMap emap = new ExecutionPropertyMap(EXEc_MAP_ID); emap.put(ResourceAntiAffinityProperty.of(antiAffinityGroup)); final Task task0 = mockTask(0, emap); final Task task1 = mockTask(1, emap); final Task task2 = mockTask(2, emap); final ExecutorRepresenter e0 = mockExecutorRepresenter(task0); assertEquals(false, schedulingConstraint.testSchedulability(e0, task1)); assertEquals(true, schedulingConstraint.testSchedulability(e0, task2)); }