// Start live computation and collect the initial result
marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), 2);
client.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().get()));
final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
assertEquals(ViewProcessState.RUNNING, viewProcess.getState());
final ViewProcessWorker worker = env.getCurrentWorker(viewProcess);
resultListener1.assertViewDefinitionCompiled(TIMEOUT);
resultListener1.assertCycleStarted(TIMEOUT);
resultListener1.assertCycleFragmentCompleted(TIMEOUT);
resultListener1.assertCycleCompleted(TIMEOUT);
assertEquals(0, resultListener1.getQueueSize());
// Push through a second result
marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), 3);
worker.requestCycle();
resultListener1.assertCycleStarted(TIMEOUT);
resultListener1.assertCycleFragmentCompleted(TIMEOUT);
resultListener1.assertCycleCompleted(TIMEOUT);
assertEquals(0, resultListener1.getQueueSize());
// Change listener
final TestViewResultListener resultListener2 = new TestViewResultListener();
client.setResultListener(resultListener2);
// Push through a result which should arrive at the new listener
worker.requestCycle();
resultListener2.assertCycleStarted(TIMEOUT);
resultListener2.assertCycleFragmentCompleted(TIMEOUT);
resultListener2.assertCycleCompleted(TIMEOUT);
assertEquals(0, resultListener1.getQueueSize());
assertEquals(0, resultListener2.getQueueSize());
client.setResultListener(null);
client.shutdown();
assertEquals(ViewProcessState.TERMINATED, viewProcess.getState());
vp.stop();
}