@Test void testPickBestResponse() { SchedulingConfig schedulerConfig = mock(SchedulingConfig.class); doReturn(schedulerConfig).when(config).getRoot(); ScoreCalculator calculator = new ScoreCalculator(config.getRoot()); PlaceResponse better = new PlaceResponse(PlaceResultCode.OK); PlaceResponse worse = new PlaceResponse(PlaceResultCode.OK); doReturn(1.0).when(schedulerConfig).getUtilizationTransferRatio(); better.setScore(new Score(2, 0)); worse.setScore(new Score(1, 0)); Set<PlaceResponse> responses = ImmutableSet.of(better, worse); assertThat(calculator.pickBestResponse(responses), is(better)); doReturn(0.0).when(schedulerConfig).getUtilizationTransferRatio(); better.setScore(new Score(1, 1)); worse.setScore(new Score(2, 0)); responses = ImmutableSet.of(better, worse); assertThat(calculator.pickBestResponse(responses), is(better)); }
public PlaceResponse pickBestResponse(Set<PlaceResponse> responses) { if (responses == null || responses.isEmpty()) { return null; } return scoreOrdering.reverse().sortedCopy(responses).get(0); }
ScoreCalculator { public PlaceResponse pickBestResponse(Set<PlaceResponse> responses) { if (responses == null || responses.isEmpty()) { return null; } return scoreOrdering.reverse().sortedCopy(responses).get(0); } }
ScoreCalculator { public PlaceResponse pickBestResponse(Set<PlaceResponse> responses) { if (responses == null || responses.isEmpty()) { return null; } return scoreOrdering.reverse().sortedCopy(responses).get(0); } ScoreCalculator(SchedulingConfig config); }
ScoreCalculator { public PlaceResponse pickBestResponse(Set<PlaceResponse> responses) { if (responses == null || responses.isEmpty()) { return null; } return scoreOrdering.reverse().sortedCopy(responses).get(0); } ScoreCalculator(SchedulingConfig config); PlaceResponse pickBestResponse(Set<PlaceResponse> responses); }
ScoreCalculator { public PlaceResponse pickBestResponse(Set<PlaceResponse> responses) { if (responses == null || responses.isEmpty()) { return null; } return scoreOrdering.reverse().sortedCopy(responses).get(0); } ScoreCalculator(SchedulingConfig config); PlaceResponse pickBestResponse(Set<PlaceResponse> responses);  }