StatusModule extends Module { @Override public void stop() { logger.trace("Stopping status module."); timer.cancel(); } StatusModule(ModuleConfiguration configuration, List<Reporter> reporters,
            final GlobalConfiguration globalConfiguration); @Override void stop();  }
@Test public void should_load_default_configuration_and_initialize() throws ConfigurationException { InfoProvider infoProvider = mock(InfoProvider.class); when(infoProvider.getCompactions()).thenReturn(new ArrayList<CompactionInfo>()); when(infoProvider.getCompactionSettingsInfo()).thenReturn(getCompactionSettingsInfo()); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final StatusModule module = new StatusModule(testConfiguration(1, true, true, true, true), testReporters(), GlobalConfiguration.getDefault()); module.stop(); PowerMockito.verifyStatic(); }
@Test public void should_report_compaction_info_when_started() throws ConfigurationException, InterruptedException { InfoProvider infoProvider = mock(InfoProvider.class); when(infoProvider.getCompactions()).thenReturn(getCompactions()); when(infoProvider.getCompactionSettingsInfo()).thenReturn(getCompactionSettingsInfo()); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final CountDownLatch latch = new CountDownLatch(2); final LatchTestReporter testReporter = new LatchTestReporter(null, GlobalConfiguration.getDefault(), latch); final List<Reporter> reporters = new ArrayList<Reporter>() { { add(testReporter); } }; final StatusModule module = new StatusModule(testConfiguration(1, true, false, false, false), reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(1000, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isTrue(); assertThat(testReporter.getReported().size()).isEqualTo(2); }
@Test public void should_report_thread_pool_info_when_started() throws ConfigurationException, InterruptedException { InfoProvider infoProvider = mock(InfoProvider.class); when(infoProvider.getTPStats()).thenReturn(getTPStats()); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final CountDownLatch latch = new CountDownLatch(3); final LatchTestReporter testReporter = new LatchTestReporter(null, GlobalConfiguration.getDefault(), latch); final List<Reporter> reporters = new ArrayList<Reporter>() { { add(testReporter); } }; final StatusModule module = new StatusModule(testConfiguration(1, false, true, false, false), reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(1100, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isTrue(); assertThat(testReporter.getReported().size()).isEqualTo(3); }
@Test public void should_report_repair_info_when_started() throws ConfigurationException, InterruptedException { InfoProvider infoProvider = mock(InfoProvider.class); when(infoProvider.getRepairSessions()).thenReturn(getRepairSessions()); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final CountDownLatch latch = new CountDownLatch(1); final LatchTestReporter testReporter = new LatchTestReporter(null, GlobalConfiguration.getDefault(), latch); final List<Reporter> reporters = new ArrayList<Reporter>() { { add(testReporter); } }; final StatusModule module = new StatusModule(testConfiguration(1, false, false, true, false), reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(1100, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isTrue(); assertThat(testReporter.getReported().size()).isEqualTo(1); }
@Test public void should_not_report_compactions_when_disabled() throws ConfigurationException, InterruptedException { InfoProvider infoProvider = mock(InfoProvider.class); when(infoProvider.getCompactions()).thenReturn(getCompactions()); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final CountDownLatch latch = new CountDownLatch(1); final LatchTestReporter testReporter = new LatchTestReporter(null, GlobalConfiguration.getDefault(), latch); final List<Reporter> reporters = new ArrayList<Reporter>() { { add(testReporter); } }; final StatusModule module = new StatusModule(testConfiguration(1, false, false, false, false), reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(1100, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isFalse(); assertThat(testReporter.getReported().size()).isEqualTo(0); }
@Test public void should_not_report_node_info_when_disabled() throws ConfigurationException, InterruptedException { InfoProvider infoProvider = mock(InfoProvider.class); NodeInfo nodeInfo = new NodeInfo(false, false, false, 0, 0); when(infoProvider.getNodeInfo()).thenReturn(nodeInfo); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final CountDownLatch latch = new CountDownLatch(1); final LatchTestReporter testReporter = new LatchTestReporter(null, GlobalConfiguration.getDefault(), latch); final List<Reporter> reporters = new ArrayList<Reporter>() { { add(testReporter); } }; final StatusModule module = new StatusModule(testConfiguration(1, false, false, false, false), reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(1100, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isFalse(); assertThat(testReporter.getReported().size()).isEqualTo(0); }
@Test public void should_report_node_info_when_enabled() throws ConfigurationException, InterruptedException { InfoProvider infoProvider = mock(InfoProvider.class); NodeInfo nodeInfo = new NodeInfo(true, false, true, 10, 10); when(infoProvider.getNodeInfo()).thenReturn(nodeInfo); PowerMockito.mockStatic(DiagnosticsAgent.class); PowerMockito.when(DiagnosticsAgent.getInfoProvider()).thenReturn(infoProvider); final CountDownLatch latch = new CountDownLatch(1); final LatchTestReporter testReporter = new LatchTestReporter(null, GlobalConfiguration.getDefault(), latch); final List<Reporter> reporters = new ArrayList<Reporter>() { { add(testReporter); } }; final StatusModule module = new StatusModule(testConfiguration(1, false, false, false, true), reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(1100, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isTrue(); assertThat(testReporter.getReported().size()).isEqualTo(1); }