@Test public void testCollectMetrics() { ListenableScheduledFuture<?> mockFuture = mock(ListenableScheduledFuture.class); doReturn(mockFuture).when(mockSchedulerService).scheduleTaskAtFixedRate(any(), anyLong(), anyLong()); CpuDataCollector mockCPUCollector = mock(CpuDataCollector.class); doReturn(OptionalDouble.of(0.123d)).when(mockCPUCollector).getControllerCpu(); doReturn(OptionalDouble.of(0.456d)).when(mockCPUCollector).getMachineCpu(); try (ControllerMetricCollector collector = new ControllerMetricCollector(mockSpiService, mockSchedulerService, mockCPUCollector, POLL_INTERVAL)) { collector.init(); runScheduledTask(); verifyMetric(storedRecords, CPU_USAGE_NAME, CONTROLLER_ID, mockCPUCollector.getControllerCpu()); verifyMetric(storedRecords, CPU_USAGE_NAME, MACHINE_ID, mockCPUCollector.getMachineCpu()); verifyMetric(storedRecords, MEMORY_USAGE_NAME, CONTROLLER_ID, OptionalDouble.empty()); assertEquals(3, storedRecords.size()); } verify(mockFuture).cancel(anyBoolean()); }
@PostConstruct public void init() { scheduledFuture = schedulerService.scheduleTaskAtFixedRate(this::poll, pollInterval, pollInterval); LOG.info("Controller Metrics Collector started"); }
ControllerMetricCollector implements AutoCloseable { @PostConstruct public void init() { scheduledFuture = schedulerService.scheduleTaskAtFixedRate(this::poll, pollInterval, pollInterval); LOG.info("Controller Metrics Collector started"); } }
ControllerMetricCollector implements AutoCloseable { @PostConstruct public void init() { scheduledFuture = schedulerService.scheduleTaskAtFixedRate(this::poll, pollInterval, pollInterval); LOG.info("Controller Metrics Collector started"); } @Inject  ControllerMetricCollector(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService); @VisibleForTesting  ControllerMetricCollector(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService, final CpuDataCollector cpuDataCollector, final long pollInterval); }
ControllerMetricCollector implements AutoCloseable { @PostConstruct public void init() { scheduledFuture = schedulerService.scheduleTaskAtFixedRate(this::poll, pollInterval, pollInterval); LOG.info("Controller Metrics Collector started"); } @Inject  ControllerMetricCollector(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService); @VisibleForTesting  ControllerMetricCollector(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService, final CpuDataCollector cpuDataCollector, final long pollInterval); @PostConstruct void init(); @Override @PreDestroy @SuppressWarnings("checkstyle:IllegalCatch") void close(); }
ControllerMetricCollector implements AutoCloseable { @PostConstruct public void init() { scheduledFuture = schedulerService.scheduleTaskAtFixedRate(this::poll, pollInterval, pollInterval); LOG.info("Controller Metrics Collector started"); } @Inject  ControllerMetricCollector(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService); @VisibleForTesting  ControllerMetricCollector(final TsdrCollectorSpiService collectorSPIService,
            final SchedulerService schedulerService, final CpuDataCollector cpuDataCollector, final long pollInterval); @PostConstruct void init(); @Override @PreDestroy @SuppressWarnings("checkstyle:IllegalCatch") void close();  }