@Test public void testNegative() throws Exception { analyzer = new CriticalAnalyzerImpl().setTimeout(10, TimeUnit.MILLISECONDS).setCheckTime(5, TimeUnit.MILLISECONDS); CriticalComponent component = new CriticalComponentImpl(analyzer, 1); analyzer.add(component); component.enterCritical(0); component.leaveCritical(0); CountDownLatch latch = new CountDownLatch(1); analyzer.start(); analyzer.addAction((CriticalComponent comp) -> { System.out.println("component " + comp + " received"); latch.countDown(); }); Assert.assertFalse(latch.await(100, TimeUnit.MILLISECONDS)); analyzer.stop(); }
@Test public void testActionOnImpl() throws Exception { analyzer = new CriticalAnalyzerImpl().setTimeout(10, TimeUnit.MILLISECONDS).setCheckTime(5, TimeUnit.MILLISECONDS); CriticalComponent component = new CriticalComponentImpl(analyzer, 2); analyzer.add(component); component.enterCritical(0); component.leaveCritical(0); component.enterCritical(1); CountDownLatch latch = new CountDownLatch(1); analyzer.start(); analyzer.addAction((CriticalComponent comp) -> { System.out.println("component " + comp + " received"); latch.countDown(); }); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); analyzer.stop(); }