SmartHostSelectionStrategy extends RandomHostSelectionStrategy implements UpdatableSelectionStrategy { @Override public Region selectRegion(List<Region> allRegions, List<Region> unvisitedRegions) { return selectRandom(allRegions, this::toFreePercentage); }  void updateHubSummaries(List<HubSummary> hubSummaries, long timestamp); @Override long getTimestamp(); @Override Map<String, Integer> getHubs(); @Override Region selectRegion(List<Region> allRegions, List<Region> unvisitedRegions); @Override Host selectHost(List<Host> hosts); boolean isUpdatedRecently(HubSummary hub);  }
@Test public void testSelectRegion() { strategy.updateHubSummaries(singletonList(SUMMARY_2), currentTimeMillis()); List<Region> allRegions = asList(REGION_1, REGION_2).stream().map(Region::copy).collect(toList()); List<Region> unvisitedRegions = new ArrayList<>(allRegions); Region actual = strategy.selectRegion(allRegions, unvisitedRegions); assertThat(actual, is(equalTo(allRegions.get(1)))); unvisitedRegions.remove(1); actual = strategy.selectRegion(allRegions, unvisitedRegions); assertThat(actual, is(equalTo(allRegions.get(1)))); allRegions.get(1).getHosts().clear(); actual = strategy.selectRegion(allRegions, unvisitedRegions); assertThat(actual, is(equalTo(allRegions.get(0)))); }