final TestViewResultListener resultListener = new TestViewResultListener();
client.setResultListener(resultListener);
final Instant time0 = Instant.now();
final ViewCycleExecutionOptions defaultCycleOptions = ViewCycleExecutionOptions.builder().setMarketDataSpecification(MarketData.live()).create();
final ViewExecutionOptions executionOptions = new ExecutionOptions(ArbitraryViewCycleExecutionSequence.of(time0, time0.plusMillis(10), time0.plusMillis(20), time0.plusMillis(30)), ExecutionFlags
.none().get(), defaultCycleOptions);
client.attachToViewProcess(env.getViewDefinition().getUniqueId(), executionOptions);
final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
final ViewProcessWorker worker = env.getCurrentWorker(viewProcess);
final CompiledViewDefinitionWithGraphsImpl compilationModel1 = (CompiledViewDefinitionWithGraphsImpl) resultListener.getViewDefinitionCompiled(Timeout.standardTimeoutMillis())
.getCompiledViewDefinition();
assertEquals(time0, resultListener.getCycleCompleted(10 * Timeout.standardTimeoutMillis()).getFullResult().getViewCycleExecutionOptions().getValuationTime());
worker.requestCycle();
assertEquals(time0.plusMillis(10), resultListener.getCycleCompleted(10 * Timeout.standardTimeoutMillis()).getFullResult().getViewCycleExecutionOptions().getValuationTime());
resultListener.assertNoCalls(Timeout.standardTimeoutMillis());
// TODO: This test doesn't belong here; it is specific to the SingleThreadViewComputationJob.
// Trick the compilation job into thinking it needs to rebuilt after time0 + 20
final CompiledViewDefinitionWithGraphsImpl compiledViewDefinition = new CompiledViewDefinitionWithGraphsImpl(VersionCorrection.LATEST, "", compilationModel1.getViewDefinition(),
CompiledViewDefinitionWithGraphsImpl.getDependencyGraphs(compilationModel1), Collections.<ComputationTargetReference, UniqueId>emptyMap(), compilationModel1.getPortfolio(),
compilationModel1.getFunctionInitId()) {
@Override
public Instant getValidTo() {
return time0.plusMillis(20);
}
};
((SingleThreadViewProcessWorker) worker).cacheCompiledViewDefinition(compiledViewDefinition);
// Running at time0 + 20 doesn't require a rebuild - should still use our dummy
worker.requestCycle();
assertEquals(time0.plusMillis(20), resultListener.getCycleCompleted(10 * Timeout.standardTimeoutMillis()).getFullResult().getViewCycleExecutionOptions().getValuationTime());
resultListener.assertNoCalls();
// time0 + 30 requires a rebuild
worker.requestCycle();
final CompiledViewDefinition compilationModel2 = resultListener.getViewDefinitionCompiled(Timeout.standardTimeoutMillis()).getCompiledViewDefinition();
assertNotSame(compilationModel1, compilationModel2);
assertNotSame(compiledViewDefinition, compilationModel2);
assertEquals(time0.plusMillis(30), resultListener.getCycleCompleted(Timeout.standardTimeoutMillis()).getFullResult().getViewCycleExecutionOptions().getValuationTime());
resultListener.assertProcessCompleted(Timeout.standardTimeoutMillis());
resultListener.assertNoCalls(Timeout.standardTimeoutMillis());
assertTrue(executionOptions.getExecutionSequence().isEmpty());
// Job should have terminated automatically with no further evaluation times
assertEquals(ViewProcessState.FINISHED, viewProcess.getState());
assertTrue(worker.isTerminated());