@Override
protected void testImpl(final Function2<ParallelRecompilationViewProcessWorker, ViewExecutionOptions, Void> callback) throws InterruptedException {
final ExecutorService executor = Executors.newCachedThreadPool();
try {
final Map<ComputationTargetReference, UniqueId> resolutions = new HashMap<ComputationTargetReference, UniqueId>();
resolutions.put(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO, UniqueId.of("Test", "0")), UniqueId.of("Test", "0", "0"));
final ChangeManager changeManager = new BasicChangeManager();
final ComputationTargetResolver targetResolver = Mockito.mock(ComputationTargetResolver.class);
Mockito.when(targetResolver.changeManager()).thenReturn(changeManager);
final FunctionCompilationContext ctx = new FunctionCompilationContext();
ctx.setRawComputationTargetResolver(targetResolver);
final CompiledFunctionService cfs = Mockito.mock(CompiledFunctionService.class);
Mockito.when(cfs.getFunctionCompilationContext()).thenReturn(ctx);
final ViewProcessContext vpContext = Mockito.mock(ViewProcessContext.class);
Mockito.when(vpContext.getFunctionCompilationService()).thenReturn(cfs);
final MockContext context = new MockContext(vpContext);
final ViewExecutionOptions options = ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().ignoreCompilationValidity().get());
final ViewDefinition viewDefinition = Mockito.mock(ViewDefinition.class);
final ParallelRecompilationViewProcessWorker worker = new ParallelRecompilationViewProcessWorker(workerFactory(executor, resolutions), context, options, viewDefinition);
callback.execute(worker, options);
s_logger.debug("Waiting for initial compilation");
assertEquals(context.event(), "view definition compiled"); // From primary worker
for (int j = 0; j < 5; j++) {
// Expect a sequence of operations
for (int i = 0; i < 3; i++) {
s_logger.debug("Waiting for cycle to start");
assertEquals(context.event(), "cycle started"); // From primary worker
s_logger.info("Cycle started");
assertEquals(context.event(), "cycle fragment completed");
s_logger.info("Cycle fragment completed");
assertEquals(context.event(), "cycle completed");
s_logger.info("Cycle completed");
}
// Signal change ...
s_logger.debug("Signalling change");
resolutions.put(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO, UniqueId.of("Test", "0")), UniqueId.of("Test", "0", Integer.toString(j + 1)));
changeManager.entityChanged(ChangeType.CHANGED, ObjectId.of("Test", "0"), Instant.now(), Instant.now(), Instant.now());
s_logger.info("Change signalled");
// ... and expect a view definition compiled to interrupt the sequence
String event = context.event();
for (int i = 0; i < 20; i++) {