ContainerTypeAwareSchedulingConstraint implements SchedulingConstraint { @Override public boolean testSchedulability(final ExecutorRepresenter executor, final Task task) { final String executorPlacementPropertyValue = task.getPropertyValue(ResourcePriorityProperty.class) .orElse(ResourcePriorityProperty.NONE); return executorPlacementPropertyValue.equals(ResourcePriorityProperty.NONE) ? true : executor.getContainerType().equals(executorPlacementPropertyValue); } @Inject private  ContainerTypeAwareSchedulingConstraint(); @Override boolean testSchedulability(final ExecutorRepresenter executor, final Task task);  }
@Test public void testContainerTypeAware() throws InjectionException { final SchedulingConstraint schedulingConstraint = Tang.Factory.getTang().newInjector() .getInstance(ContainerTypeAwareSchedulingConstraint.class); final ExecutorRepresenter a0 = mockExecutorRepresenter(ResourcePriorityProperty.TRANSIENT); final ExecutorRepresenter a1 = mockExecutorRepresenter(ResourcePriorityProperty.RESERVED); final ExecutorRepresenter a2 = mockExecutorRepresenter(ResourcePriorityProperty.NONE); final Task task1 = mock(Task.class); when(task1.getPropertyValue(ResourcePriorityProperty.class)) .thenReturn(Optional.of(ResourcePriorityProperty.RESERVED)); final Set<ExecutorRepresenter> executorRepresenterList1 = new HashSet<>(Arrays.asList(a0, a1, a2)); final Set<ExecutorRepresenter> candidateExecutors1 = executorRepresenterList1.stream() .filter(e -> schedulingConstraint.testSchedulability(e, task1)) .collect(Collectors.toSet()); ; final Set<ExecutorRepresenter> expectedExecutors1 = Collections.singleton(a1); assertEquals(expectedExecutors1, candidateExecutors1); final Task task2 = mock(Task.class); when(task2.getPropertyValue(ResourcePriorityProperty.class)) .thenReturn(Optional.of(ResourcePriorityProperty.NONE)); final Set<ExecutorRepresenter> executorRepresenterList2 = new HashSet<>(Arrays.asList(a0, a1, a2)); final Set<ExecutorRepresenter> candidateExecutors2 = executorRepresenterList2.stream() .filter(e -> schedulingConstraint.testSchedulability(e, task2)) .collect(Collectors.toSet()); final Set<ExecutorRepresenter> expectedExecutors2 = new HashSet<>(Arrays.asList(a0, a1, a2)); assertEquals(expectedExecutors2, candidateExecutors2); }