IntervalRegistryLogger { protected Map<String, Long> getTopElements(Map<String, Long> countMap) { MinMaxPriorityQueue<Map.Entry<String, Long>> topQueue = MinMaxPriorityQueue .orderedBy(Comparator.comparing((Function<Map.Entry<String, Long>, Long>) Map.Entry::getValue).reversed()) .maximumSize(topSize) .create(countMap.entrySet()); return topQueue.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } IntervalRegistryLogger(@Value("${quota.log.topSize}") int topSize, @Value("${quota.log.intervalMin}") long logIntervalMin,
                                  HostRequestIntervalRegistry intervalRegistry); void schedule(); void stop(); void logStatistic();  }
@Test public void onlyMaxHostsCollected() { Map<String, Long> map = ImmutableMap.of("a", 8L, "b", 3L, "c", 1L, "d", 3L); Map<String, Long> actual = logger.getTopElements(map); Map<String, Long> expected = ImmutableMap.of("a", 8L, "b", 3L, "d", 3L); assertEquals(expected, actual); }
@Test public void emptyMapProcessedCorrectly() { Map<String, Long> map = Collections.emptyMap(); Map<String, Long> actual = logger.getTopElements(map); Map<String, Long> expected = Collections.emptyMap(); assertEquals(expected, actual); }