FreeSlotSchedulingConstraint implements SchedulingConstraint { @Override public boolean testSchedulability(final ExecutorRepresenter executor, final Task task) { if (!task.getPropertyValue(ResourceSlotProperty.class).orElse(false)) { return true; } return executor.getNumOfComplyingRunningTasks() < executor.getExecutorCapacity(); } @Inject private  FreeSlotSchedulingConstraint(); @Override boolean testSchedulability(final ExecutorRepresenter executor, final Task task);  }
@Test public void testFreeSlot() { final Task task = mock(Task.class); when(task.getPropertyValue(ResourceSlotProperty.class)).thenReturn(Optional.of(true)); final Set<ExecutorRepresenter> executorRepresenterList = new HashSet<>(Arrays.asList(a0, a1)); final Set<ExecutorRepresenter> candidateExecutors = executorRepresenterList.stream() .filter(e -> schedulingConstraint.testSchedulability(e, task)) .collect(Collectors.toSet()); final Set<ExecutorRepresenter> expectedExecutors = Collections.singleton(a1); assertEquals(expectedExecutors, candidateExecutors); }
@Test public void testIgnoringSlot() { final Task task = mock(Task.class); when(task.getPropertyValue(ResourceSlotProperty.class)).thenReturn(Optional.of(false)); final Set<ExecutorRepresenter> executorRepresenterList = new HashSet<>(Arrays.asList(a0, a1)); final Set<ExecutorRepresenter> candidateExecutors = executorRepresenterList.stream() .filter(e -> schedulingConstraint.testSchedulability(e, task)) .collect(Collectors.toSet()); final Set<ExecutorRepresenter> expectedExecutors = new HashSet<>(Arrays.asList(a0, a1)); assertEquals(expectedExecutors, candidateExecutors); }