RateLimitingMergingViewProcessListener extends MergingViewProcessListener { public void setPaused(boolean isPaused) { final Call<?> drain; _taskSetupLock.lock(); try { if (_isPaused == isPaused) { return; } _isPaused = isPaused; drain = updateConfiguration(); } finally { _taskSetupLock.unlock(); } invoke(drain); } RateLimitingMergingViewProcessListener(ViewResultListener underlying, EngineResourceManagerInternal<?> cycleManager, ScheduledExecutorService timer); void terminate(); boolean isPaused(); void setPaused(boolean isPaused); long getMinimumUpdatePeriodMillis(); void setMinimumUpdatePeriodMillis(long minimumUpdatePeriodMillis);  }
@Test public void testPassThrough() { final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); try { final TestViewResultListener testListener = new TestViewResultListener(); final RateLimitingMergingViewProcessListener mergingListener = new RateLimitingMergingViewProcessListener(testListener, mock(EngineResourceManagerImpl.class), executor); addCompile(mergingListener); addResults(mergingListener, 1000); testListener.assertViewDefinitionCompiled(); testListener.assertMultipleCycleCompleted(1000); testListener.assertNoCalls(); mergingListener.setPaused(true); addResults(mergingListener, 1000); testListener.assertNoCalls(); mergingListener.setPaused(false); testListener.assertCycleCompleted(); testListener.assertNoCalls(); mergingListener.setPaused(false); addResults(mergingListener, 1000); testListener.assertMultipleCycleCompleted(1000); mergingListener.processTerminated(false); testListener.assertProcessTerminated(); testListener.assertNoCalls(); mergingListener.processTerminated(false); } finally { executor.shutdown(); } }
@Test public void testCallOrderingAndCollapsing() throws InterruptedException { final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); try { final TestViewResultListener testListener = new TestViewResultListener(); final RateLimitingMergingViewProcessListener mergingListener = new RateLimitingMergingViewProcessListener(testListener, mock(EngineResourceManagerImpl.class), executor); mergingListener.setPaused(true); testListener.assertNoCalls(); addCompile(mergingListener); addResults(mergingListener, 10); final CompiledViewDefinitionWithGraphsImpl preCompilation = mock(CompiledViewDefinitionWithGraphsImpl.class); mergingListener.viewDefinitionCompiled(preCompilation, true); addResults(mergingListener, 10); final InMemoryViewComputationResultModel initialResult = new InMemoryViewComputationResultModel(); initialResult.setCalculationTime(now()); mergingListener.cycleCompleted(initialResult, getDeltaResult(1)); final InMemoryViewComputationResultModel latestResult = new InMemoryViewComputationResultModel(); latestResult.setCalculationTime(now()); mergingListener.cycleCompleted(latestResult, getDeltaResult(2)); final CompiledViewDefinitionWithGraphsImpl postCompilation = mock(CompiledViewDefinitionWithGraphsImpl.class); mergingListener.viewDefinitionCompiled(postCompilation, true); mergingListener.processCompleted(); mergingListener.processTerminated(false); mergingListener.setPaused(false); testListener.assertViewDefinitionCompiled(Timeout.standardTimeoutMillis(), preCompilation); final ViewDeltaResultModel mergedDelta = testListener.getCycleCompleted(Timeout.standardTimeoutMillis()).getDeltaResult(); assertEquals(2, mergedDelta.getAllResults().size()); final Set<Pair<String, Integer>> results = new HashSet<Pair<String, Integer>>(); for (final ViewResultEntry deltaItem : mergedDelta.getAllResults()) { results.add(Pairs.of(deltaItem.getComputedValue().getSpecification().getValueName(), (Integer) deltaItem.getComputedValue().getValue())); } assertTrue(results.contains(Pairs.of("value1", 1))); assertTrue(results.contains(Pairs.of("value2", 2))); testListener.assertViewDefinitionCompiled(Timeout.standardTimeoutMillis(), postCompilation); testListener.assertProcessCompleted(); testListener.assertProcessTerminated(); testListener.assertNoCalls(); } finally { executor.shutdown(); } }