@Test public void getProcessorReturnsCorrectWithMultpleStats() { ProcessorHolder processorHolder1 = new ProcessorHolder(); processorHolder1.setProcessor(Mockito.mock(Processor.class)); ProcessorHolder processorHolder2 = new ProcessorHolder(); processorHolder2.setProcessor(Mockito.mock(Processor.class)); ProcessorHolder processorHolder3 = new ProcessorHolder(); processorHolder3.setProcessor(Mockito.mock(Processor.class)); RouteStatistics stat1 = new RouteStatistics(); stat1.setProcessorHolder(processorHolder1); stat1.setMeanProcessingTime(12345L); RouteStatistics stat2 = new RouteStatistics(); stat2.setProcessorHolder(processorHolder2); stat2.setMeanProcessingTime(1L); RouteStatistics stat3 = new RouteStatistics(); stat3.setProcessorHolder(processorHolder3); stat3.setMeanProcessingTime(54321L); List<RouteStatistics> stats = new ArrayList<RouteStatistics>(); stats.add(stat1); stats.add(stat2); stats.add(stat3); List<Processor> processors = new LinkedList<Processor>(); processors.add(processorHolder1.getProcessor()); processors.add(processorHolder2.getProcessor()); processors.add(processorHolder3.getProcessor()); ProcessorSelectorStrategy strategy = new MeanProcessingTimeProcessorSelectorStrategy(); Processor processor = strategy.getProcessor(stats); Assert.assertNotNull(processor); Assert.assertEquals(processorHolder2.getProcessor(), processor); }
@Override public Processor getProcessor(List<RouteStatistics> stats) { RouteStatistics best = null; for (RouteStatistics current : stats) { if (best == null) { best = current; } best = best.getMeanProcessingTime() <= current.getMeanProcessingTime() ? best : current; } LOG.debug("Found '{}' is the best processor", best); return best.getProcessorHolder().getProcessor(); }
MeanProcessingTimeProcessorSelectorStrategy implements ProcessorSelectorStrategy { @Override public Processor getProcessor(List<RouteStatistics> stats) { RouteStatistics best = null; for (RouteStatistics current : stats) { if (best == null) { best = current; } best = best.getMeanProcessingTime() <= current.getMeanProcessingTime() ? best : current; } LOG.debug("Found '{}' is the best processor", best); return best.getProcessorHolder().getProcessor(); } }
MeanProcessingTimeProcessorSelectorStrategy implements ProcessorSelectorStrategy { @Override public Processor getProcessor(List<RouteStatistics> stats) { RouteStatistics best = null; for (RouteStatistics current : stats) { if (best == null) { best = current; } best = best.getMeanProcessingTime() <= current.getMeanProcessingTime() ? best : current; } LOG.debug("Found '{}' is the best processor", best); return best.getProcessorHolder().getProcessor(); }  }
MeanProcessingTimeProcessorSelectorStrategy implements ProcessorSelectorStrategy { @Override public Processor getProcessor(List<RouteStatistics> stats) { RouteStatistics best = null; for (RouteStatistics current : stats) { if (best == null) { best = current; } best = best.getMeanProcessingTime() <= current.getMeanProcessingTime() ? best : current; } LOG.debug("Found '{}' is the best processor", best); return best.getProcessorHolder().getProcessor(); }  @Override Processor getProcessor(List<RouteStatistics> stats); @Override List<Integer> getWeightedProcessors(List<RouteStatistics> stats, List<Processor> processors); }
MeanProcessingTimeProcessorSelectorStrategy implements ProcessorSelectorStrategy { @Override public Processor getProcessor(List<RouteStatistics> stats) { RouteStatistics best = null; for (RouteStatistics current : stats) { if (best == null) { best = current; } best = best.getMeanProcessingTime() <= current.getMeanProcessingTime() ? best : current; } LOG.debug("Found '{}' is the best processor", best); return best.getProcessorHolder().getProcessor(); }  @Override Processor getProcessor(List<RouteStatistics> stats); @Override List<Integer> getWeightedProcessors(List<RouteStatistics> stats, List<Processor> processors);  }