@Test public void testStatMonitorNotifierAliveButWaiting() throws Exception { StatMonitorHandler handler = new StatMonitorHandler(); TestStatisticsMonitor monitor = new TestStatisticsMonitor(); handler.addMonitor(monitor); final StatMonitorNotifier notifier = handler.getStatMonitorNotifier(); assertTrue(notifier.isAlive()); waitUntilWaiting(notifier); for (int i = 0; i < 20; i++) { assertTrue(notifier.isWaiting()); Thread.sleep(10); } }
@Test public void testGetStatMonitorHandler() { StatMonitorHandler handler = SampleCollector.getStatMonitorHandler(); assertNotNull(handler); assertTrue(handler.getMonitorsSnapshot().isEmpty()); assertNull(handler.getStatMonitorNotifier()); }
@Test public void testStatMonitorNotifierWakesUpForWork() throws Exception { StatMonitorHandler handler = new StatMonitorHandler(); TestStatisticsMonitor monitor = new TestStatisticsMonitor(); handler.addMonitor(monitor); final StatMonitorNotifier notifier = handler.getStatMonitorNotifier(); assertTrue(notifier.isAlive()); waitUntilWaiting(notifier); // if notification occurs then notifier woke up... assertEquals(0, monitor.getNotificationCount()); handler.sampled(NanoTimer.getTime(), Collections.<ResourceInstance>emptyList()); waitForNotificationCount(monitor, 1, 2 * 1000, 10, false); assertEquals(1, monitor.getNotificationCount()); // and goes back to waiting... waitUntilWaiting(notifier); }