@Test public void testHasTooManyRunningSlots() { SlotState scheduledSlot1 = new SlotState(slot1, READY); List<SlotState> input = Arrays .asList(new SlotState[] { new SlotState(slot1, RUNNING), scheduledSlot1, new SlotState(slot3, SUCCESS), new SlotState(slot3, RUNNING), new SlotState(slot3, RUNNING) }); List<SlotState> expected = Arrays.asList(new SlotState[] { }); SchedulingStrategy strategy = makeSerialSchedulingStrategyConcurrent(); Assert.assertEquals(expected, strategy.getSchedulingCandidates(input)); }
@Override public List<SlotState> getSchedulingCandidates(List<SlotState> states) { int slotsRunning = CollectionUtils.countMatches(states, RUNNING_PREDICATE); if (slotsRunning >= concurrencyLevel) { return Collections.emptyList(); } @SuppressWarnings("unchecked") Collection<SlotState> candidates = CollectionUtils.select(states, CANDIDATE_PREDICATE); if (!candidates.isEmpty()) { int elemsToGet = Math.min(candidates.size(), concurrencyLevel - slotsRunning); return Lists.newArrayList(candidates).subList(0, elemsToGet); } return Collections.emptyList(); }
SerialSchedulingStrategy implements SchedulingStrategy { @Override public List<SlotState> getSchedulingCandidates(List<SlotState> states) { int slotsRunning = CollectionUtils.countMatches(states, RUNNING_PREDICATE); if (slotsRunning >= concurrencyLevel) { return Collections.emptyList(); } @SuppressWarnings("unchecked") Collection<SlotState> candidates = CollectionUtils.select(states, CANDIDATE_PREDICATE); if (!candidates.isEmpty()) { int elemsToGet = Math.min(candidates.size(), concurrencyLevel - slotsRunning); return Lists.newArrayList(candidates).subList(0, elemsToGet); } return Collections.emptyList(); } }
SerialSchedulingStrategy implements SchedulingStrategy { @Override public List<SlotState> getSchedulingCandidates(List<SlotState> states) { int slotsRunning = CollectionUtils.countMatches(states, RUNNING_PREDICATE); if (slotsRunning >= concurrencyLevel) { return Collections.emptyList(); } @SuppressWarnings("unchecked") Collection<SlotState> candidates = CollectionUtils.select(states, CANDIDATE_PREDICATE); if (!candidates.isEmpty()) { int elemsToGet = Math.min(candidates.size(), concurrencyLevel - slotsRunning); return Lists.newArrayList(candidates).subList(0, elemsToGet); } return Collections.emptyList(); } SerialSchedulingStrategy(int concurrencyLevel); }
SerialSchedulingStrategy implements SchedulingStrategy { @Override public List<SlotState> getSchedulingCandidates(List<SlotState> states) { int slotsRunning = CollectionUtils.countMatches(states, RUNNING_PREDICATE); if (slotsRunning >= concurrencyLevel) { return Collections.emptyList(); } @SuppressWarnings("unchecked") Collection<SlotState> candidates = CollectionUtils.select(states, CANDIDATE_PREDICATE); if (!candidates.isEmpty()) { int elemsToGet = Math.min(candidates.size(), concurrencyLevel - slotsRunning); return Lists.newArrayList(candidates).subList(0, elemsToGet); } return Collections.emptyList(); } SerialSchedulingStrategy(int concurrencyLevel); @Override List<SlotState> getSchedulingCandidates(List<SlotState> states); int getConcurrencyLevel(); }
SerialSchedulingStrategy implements SchedulingStrategy { @Override public List<SlotState> getSchedulingCandidates(List<SlotState> states) { int slotsRunning = CollectionUtils.countMatches(states, RUNNING_PREDICATE); if (slotsRunning >= concurrencyLevel) { return Collections.emptyList(); } @SuppressWarnings("unchecked") Collection<SlotState> candidates = CollectionUtils.select(states, CANDIDATE_PREDICATE); if (!candidates.isEmpty()) { int elemsToGet = Math.min(candidates.size(), concurrencyLevel - slotsRunning); return Lists.newArrayList(candidates).subList(0, elemsToGet); } return Collections.emptyList(); } SerialSchedulingStrategy(int concurrencyLevel); @Override List<SlotState> getSchedulingCandidates(List<SlotState> states); int getConcurrencyLevel();  }