MetricsModule extends Module { @Override public void stop() { logger.trace("Stopping metrics module."); timer.cancel(); metricsCollector.close(); } MetricsModule(ModuleConfiguration configuration, List<Reporter> reporters,
            final GlobalConfiguration globalConfiguration); @Override void stop();  }
@Test public void should_load_default_configuration_and_initialize() throws ConfigurationException, InterruptedException { final ModuleConfiguration config = testConfiguration(); initializeTestMBean(config); final MetricsModule module = new MetricsModule(config, testReporters(), GlobalConfiguration.getDefault()); module.stop(); deinitializeTestMBean(); }
@Test public void should_report_metrics_when_started() throws ConfigurationException, InterruptedException { final ModuleConfiguration config = testConfiguration(); TestMXBeanImpl bean = (TestMXBeanImpl) initializeTestMBean(config); 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 MetricsModule module = new MetricsModule(config, reporters, GlobalConfiguration.getDefault()); boolean wait = latch.await(2000, TimeUnit.MILLISECONDS); module.stop(); assertThat(wait).isTrue(); assertThat(bean.called).isEqualTo(true); deinitializeTestMBean(); }