Source:
public void testGlobalSchedEventProcessorSchedulingPeriod() throws InjectionException, InterruptedException { final List<OperatorChainManager> operatorChainManagers = new ArrayList<>(3); final AtomicInteger ocm1Count = new AtomicInteger(0); final OperatorChainManager ocm1 = mock(OperatorChainManager.class); final OperatorChain operatorChain1 = mock(OperatorChain.class); when(operatorChain1.processNextEvent()).thenReturn(true); when(ocm1.pickOperatorChain()).thenAnswer((iom) -> { ocm1Count.incrementAndGet(); return operatorChain1; }); final OperatorChainManager ocm2 = mock(OperatorChainManager.class); when(ocm2.pickOperatorChain()).thenReturn(null); final AtomicInteger ocm3Count = new AtomicInteger(0); final OperatorChainManager ocm3 = mock(OperatorChainManager.class); final OperatorChain operatorChain3 = mock(OperatorChain.class); when(operatorChain3.processNextEvent()).thenReturn(true); when(ocm3.pickOperatorChain()).thenAnswer((iom) -> { ocm3Count.incrementAndGet(); return operatorChain3; }); operatorChainManagers.add(ocm1); operatorChainManagers.add(ocm2); operatorChainManagers.add(ocm3); final Object notifier = new Object(); final GlobalScheduler globalScheduler = new TestGlobalScheduler(operatorChainManagers, notifier); final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder(); jcb.bindNamedParameter(SchedulingPeriod.class, "100"); final Injector injector = Tang.Factory.getTang().newInjector(jcb.build()); injector.bindVolatileInstance(GlobalScheduler.class, globalScheduler); final EventProcessorFactory epFactory = injector.getInstance(GlobalSchedEventProcessorFactory.class); final EventProcessor eventProcessor = epFactory.newEventProcessor(); eventProcessor.start(); synchronized (notifier) { notifier.wait(); } eventProcessor.close(); verify(ocm1, times(ocm1Count.get())).pickOperatorChain(); verify(ocm2, times(1)).pickOperatorChain(); verify(ocm3, times(ocm3Count.get())).pickOperatorChain(); }

Target:
public void testGlobalSchedEventProcessorSchedulingPeriod() throws InjectionException, InterruptedException { final List<OperatorChainManager> operatorChainManagers = new ArrayList<>(3); final AtomicInteger ocm1Count = new AtomicInteger(0); final OperatorChainManager ocm1 = mock(OperatorChainManager.class); final OperatorChain operatorChain1 = mock(OperatorChain.class); when(operatorChain1.processNextEvent()).thenReturn(true); when(ocm1.pickOperatorChain()).thenAnswer((iom) -> { ocm1Count.incrementAndGet(); return operatorChain1; }); final OperatorChainManager ocm2 = mock(OperatorChainManager.class); when(ocm2.pickOperatorChain()).thenReturn(null); final AtomicInteger ocm3Count = new AtomicInteger(0); final OperatorChainManager ocm3 = mock(OperatorChainManager.class); final OperatorChain operatorChain3 = mock(OperatorChain.class); when(operatorChain3.processNextEvent()).thenReturn(true); when(ocm3.pickOperatorChain()).thenAnswer((iom) -> { ocm3Count.incrementAndGet(); return operatorChain3; }); operatorChainManagers.add(ocm1); operatorChainManagers.add(ocm2); operatorChainManagers.add(ocm3); final Object notifier = new Object(); final GlobalScheduler globalScheduler = new TestGlobalScheduler(operatorChainManagers, notifier); final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder(); jcb.bindNamedParameter(SchedulingPeriod.class, "100"); final Injector injector = Tang.Factory.getTang().newInjector(jcb.build()); injector.bindVolatileInstance(GlobalScheduler.class, globalScheduler); final EventProcessorFactory epFactory = injector.getInstance(GlobalSchedEventProcessorFactory.class); final EventProcessor eventProcessor = epFactory.newEventProcessor(); eventProcessor.start(); synchronized (notifier) { notifier.wait(); } eventProcessor.close(); Assert.assertTrue(ocm1Count.get() > 1); Assert.assertTrue(ocm3Count.get() > 1); verify(ocm1, times(ocm1Count.get())).pickOperatorChain(); verify(ocm2, times(1)).pickOperatorChain(); verify(ocm3, times(ocm3Count.get())).pickOperatorChain(); }