HeapHistogramStatisticsExecutor { public void exec() { try { Instant startTme = Instant.now(); LOGGER.info("Java Heap Histogram Statistics job started"); List<HeapHistogramService.HeapHistogramEntry> heapHistogramEntries = heapHistogramService.generateHeapHistogram(); processHistogramEntries(heapHistogramEntries); LOGGER.info("Java Heap Histogram Statistics job completed in {}", Duration.between(startTme, Instant.now()).toString()); } catch (final RuntimeException e) { LOGGER.error("Error executing scheduled Heap Histogram job", e); throw e; } } @Inject  HeapHistogramStatisticsExecutor(final HeapHistogramService heapHistogramService,
                                    final InternalStatisticsReceiver internalStatisticsReceiver,
                                    final NodeInfo nodeInfo); void exec();  }
@Test void testExec_stroomClasses() { executor.exec(); Mockito.verify(mockInternalStatisticsReceiver, Mockito.timeout(5_000).times(2)) .putEvents(eventsCaptor.capture()); List<List<InternalStatisticEvent>> argValues = eventsCaptor.getAllValues(); assertThat(argValues.get(0).size() > 0).isTrue(); assertThat(argValues.get(0).size() == argValues.get(1).size()).isTrue(); for (List<InternalStatisticEvent> statisticEvents : argValues) { assertThat(statisticEvents.stream() .map(STAT_TO_CLASS_NAME_MAPPER) .allMatch(className -> className.startsWith("stroom"))).isTrue(); Pattern thisClassPattern = Pattern.compile(this.getClass().getName()); assertThat(statisticEvents.stream() .map(STAT_TO_CLASS_NAME_MAPPER) .anyMatch(thisClassPattern.asPredicate())).isTrue(); } }
@Test void testExec_allClasses() { heapHistogramConfig.setClassNameMatchRegex(""); executor.exec(); Mockito.verify(mockInternalStatisticsReceiver, Mockito.timeout(5_000).times(2)) .putEvents(eventsCaptor.capture()); List<List<InternalStatisticEvent>> argValues = eventsCaptor.getAllValues(); assertThat(argValues.get(0).size() > 0).isTrue(); assertThat(argValues.get(0).size() == argValues.get(1).size()).isTrue(); for (List<InternalStatisticEvent> statisticEvents : argValues) { assertThat(statisticEvents.stream() .map(STAT_TO_CLASS_NAME_MAPPER) .map(className -> className.substring(0, 1)) .distinct() .count() > 1).isTrue(); } }