ParallelRecompilationViewProcessWorker implements ViewProcessWorker { @Override public void join() throws InterruptedException { s_logger.info("Joining worker(s)"); do { ViewProcessWorker primary; synchronized (this) { if (getPrimary() == null) { break; } primary = getPrimary()._worker; } s_logger.debug("Joining primary worker {}", primary); primary.join(); synchronized (this) { if (getPrimary() == null) { break; } else { if (getPrimary()._worker == primary) { if (getSecondary() != null) { promoteSecondaryWorker(); } else { _primary = null; break; } } else { s_logger.debug("Primary worker {} changed to {} during wait", primary, getPrimary()); } } } } while (true); s_logger.debug("Primary worker joined"); } ParallelRecompilationViewProcessWorker(final ViewProcessWorkerFactory delegate, final ViewProcessWorkerContext context, final ViewExecutionOptions options,
      final ViewDefinition viewDefinition); synchronized void startParallel(final ViewExecutionOptions options); synchronized void startDeferred(final ViewExecutionOptions options); synchronized void startImmediate(final ViewExecutionOptions options); @Override boolean triggerCycle(); @Override boolean requestCycle(); @Override void updateViewDefinition(ViewDefinition viewDefinition); @Override void terminate(); @Override void join(); @Override boolean join(final long timeout); @Override synchronized boolean isTerminated(); @Override void forceGraphRebuild();  }
@Test(timeOut = 10000) public void testJoin_noWorkers() throws InterruptedException { final ViewProcessWorkerFactory workerFactory = Mockito.mock(ViewProcessWorkerFactory.class); final ViewProcessWorkerContext context = Mockito.mock(ViewProcessWorkerContext.class); final ViewExecutionOptions options = ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().ignoreCompilationValidity().get()); final ViewDefinition viewDefinition = Mockito.mock(ViewDefinition.class); final ParallelRecompilationViewProcessWorker worker = new ParallelRecompilationViewProcessWorker(workerFactory, context, options, viewDefinition); worker.join(); }
@Test(timeOut = 10000) public void testJoin_timeout_noWorkers() throws InterruptedException { final ViewProcessWorkerFactory workerFactory = new ViewProcessWorkerFactory() { @Override public ViewProcessWorker createWorker(final ViewProcessWorkerContext context, final ViewExecutionOptions executionOptions, final ViewDefinition viewDefinition) { final ViewProcessWorker worker = Mockito.mock(ViewProcessWorker.class); try { Mockito.when(worker.join(Mockito.anyLong())).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { assertTrue(((Long) invocation.getArguments()[0]) <= 20000); return Boolean.TRUE; } }); } catch (InterruptedException e) { } return worker; } }; final ViewProcessWorkerContext context = Mockito.mock(ViewProcessWorkerContext.class); final ViewExecutionOptions options = ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().ignoreCompilationValidity().get()); final ViewDefinition viewDefinition = Mockito.mock(ViewDefinition.class); final ParallelRecompilationViewProcessWorker worker = new ParallelRecompilationViewProcessWorker(workerFactory, context, options, viewDefinition); assertTrue(worker.join(20000)); }