Package com.opengamma.engine.test

Examples of com.opengamma.engine.test.ViewProcessorTestEnvironment


    worker.join();
  }

  @Test
  public void testSuspend_viewExists() throws InterruptedException, ExecutionException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    env.init();
    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final Runnable resume = vp.suspend(Executors.newCachedThreadPool()).get();
    assertNotNull(resume);

    final CountDownLatch latch = new CountDownLatch(1);
    final ViewClient client2 = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    final Thread tryAttach = new Thread() {
      @Override
      public void run() {
        client2.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live()));
        client2.shutdown();
        latch.countDown();
      }
    };
    tryAttach.start();
View Full Code Here


    vp.stop();
  }

  @Test
  public void testSuspend_viewNotExists() throws InterruptedException, ExecutionException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    env.init();
    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();
    final Runnable resume = vp.suspend(Executors.newCachedThreadPool()).get();
    assertNotNull(resume);

    final ViewClient client2 = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    final CountDownLatch latch = new CountDownLatch(1);
    final Thread tryAttach = new Thread() {
      @Override
      public void run() {
        client2.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live()));
        client2.shutdown();
        latch.countDown();
      }
    };
    tryAttach.start();
View Full Code Here

    vp.stop();
  }

  @Test
  public void testCycleManagement_realTimeInterrupted() throws InterruptedException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    env.init();
    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    final CycleCountingViewResultListener listener = new CycleCountingViewResultListener(10);
    client.setResultListener(listener);
    final ViewExecutionOptions executionOptions = ExecutionOptions.of(new InfiniteViewCycleExecutionSequence(), ViewCycleExecutionOptions.builder().setMarketDataSpecification(MarketData.live())
        .create(),
        ExecutionFlags.none().runAsFastAsPossible().get());
    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), executionOptions);
    listener.awaitCycles(10 * Timeout.standardTimeoutMillis());

    final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
    final ViewProcessWorker worker = env.getCurrentWorker(viewProcess);

    client.shutdown();
    worker.join();

    assertEquals(0, vp.getViewCycleManager().getResourceCount());
View Full Code Here

@Test(groups = TestGroup.UNIT)
public class DependencyGraphBuilderTest extends AbstractFudgeBuilderTestCase {

  @Test
  public void testCycleSimpleGraph() {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    env.init();
    final CompiledViewDefinitionWithGraphsImpl compiledViewDefinition = env.compileViewDefinition(Instant.now(), VersionCorrection.LATEST);
    final DependencyGraph graph = compiledViewDefinition.getDependencyGraphExplorer(ViewProcessorTestEnvironment.TEST_CALC_CONFIG_NAME).getWholeGraph();
    final DependencyGraph cycledGraph = cycleObject(DependencyGraph.class, graph);

    assertEquals(graph.getCalculationConfigurationName(), cycledGraph.getCalculationConfigurationName());
    assertEquals(graph.getAllComputationTargets(), cycledGraph.getAllComputationTargets());
View Full Code Here

    assertEquals(0, vp.getViewCycleManager().getResourceCount());
  }

  @Test
  public void testCycleManagement_processCompletes() throws InterruptedException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    env.setViewResultListenerFactory(viewResultListenerFactoryStub);
    env.init();
    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    final ViewExecutionOptions executionOptions = ExecutionOptions.batch(generateExecutionSequence(10), ViewCycleExecutionOptions.builder().setMarketDataSpecification(MarketData.live()).create());
    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), executionOptions);
    waitForCompletionAndShutdown(vp, client, env);
    assertEquals(0, vp.getViewCycleManager().getResourceCount());
  }
View Full Code Here

    waitForCompletionAndShutdown(vp, client, env);
    assertEquals(0, vp.getViewCycleManager().getResourceCount());
  }

  public void testCycleManagement_processCompletesWithReferences() throws InterruptedException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();

    env.setViewResultListenerFactory(viewResultListenerFactoryStub);
    env.init();
    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    client.setViewCycleAccessSupported(true);
    final List<EngineResourceReference<? extends ViewCycle>> references = new ArrayList<EngineResourceReference<? extends ViewCycle>>();
    final ViewResultListener resultListener = new AbstractViewResultListener() {

      @Override
      public void cycleCompleted(final ViewComputationResultModel fullResult, final ViewDeltaResultModel deltaResult) {
        final EngineResourceReference<? extends ViewCycle> reference = client.createLatestCycleReference();
        if (reference != null) {
          references.add(reference);
        }
      }

      @Override
      public UserPrincipal getUser() {
        return UserPrincipal.getTestUser();
      }

    };
    client.setResultListener(resultListener);
    final ViewExecutionOptions executionOptions = ExecutionOptions.batch(generateExecutionSequence(10), ViewCycleExecutionOptions.builder().setMarketDataSpecification(MarketData.live()).create());
    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), executionOptions);

    final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
    final UniqueId viewProcessId = viewProcess.getUniqueId();

    waitForCompletionAndShutdown(vp, client, env);

    assertEquals(10, references.size());
View Full Code Here

    client.pause();
  }

  @Test
  public void testChangeOfListeners() throws InterruptedException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    final SynchronousInMemoryLKVSnapshotProvider marketDataProvider = new SynchronousInMemoryLKVSnapshotProvider();
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), 0);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), 0);
    env.setMarketDataProvider(marketDataProvider);
    env.init();

    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    client.setFragmentResultMode(ViewResultMode.FULL_ONLY);
    final TestViewResultListener resultListener1 = new TestViewResultListener();
    client.setResultListener(resultListener1);

    // 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());
View Full Code Here

    vp.stop();
  }

  @Test
  public void testOldRecalculationThreadDies() throws InterruptedException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    final SynchronousInMemoryLKVSnapshotProvider marketDataProvider = new SynchronousInMemoryLKVSnapshotProvider();
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), 0);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), 0);
    env.setMarketDataProvider(marketDataProvider);
    env.init();

    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);

    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().get()));
    final ViewProcessImpl viewProcess1 = env.getViewProcess(vp, client.getUniqueId());

    final ViewProcessWorker worker1 = env.getCurrentWorker(viewProcess1);
    assertFalse(worker1.isTerminated());

    client.detachFromViewProcess();
    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().get()));
    final ViewProcessImpl viewProcess2 = env.getViewProcess(vp, client.getUniqueId());
    final ViewProcessWorker worker2 = env.getCurrentWorker(viewProcess2);

    assertFalse(viewProcess1 == viewProcess2);
    assertTrue(worker1.join(TIMEOUT));

    vp.stop();
View Full Code Here

  }

  //-------------------------------------------------------------------------
  @Test
  public void testSetMinimumLogMode() throws InterruptedException {
    final ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    final SynchronousInMemoryLKVSnapshotProvider marketDataProvider = new SynchronousInMemoryLKVSnapshotProvider();
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), 0);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), 0);
    env.setMarketDataProvider(marketDataProvider);
    final InMemoryFunctionRepository functionRepository = new InMemoryFunctionRepository();

    final ComputationTarget target = new ComputationTarget(ComputationTargetType.CURRENCY, Currency.USD);
    final MockFunction fn1 = new MockFunction(MockFunction.UNIQUE_ID + "1", target) {

      @Override
      public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
        LogBridge.getInstance().log(new SimpleLogEvent(LogLevel.WARN, "Warning during execution"));
        LogBridge.getInstance().log(new SimpleLogEvent(LogLevel.ERROR, "Error during execution"));
        return super.execute(executionContext, inputs, target, desiredValues);
      }

    };
    final ValueRequirement requirement1 = new ValueRequirement("value1", target.toSpecification());
    fn1.addResult(new ValueSpecification(requirement1.getValueName(), target.toSpecification(), ValueProperties.with(ValuePropertyNames.FUNCTION, "fn1").get()), "result1");
    functionRepository.addFunction(fn1);

    final MockFunction fn2 = new MockFunction(MockFunction.UNIQUE_ID + "2", target) {

      @Override
      public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
        LogBridge.getInstance().log(new SimpleLogEvent(LogLevel.WARN, "Warning during execution"));
        return super.execute(executionContext, inputs, target, desiredValues);
      }

    };
    fn2.addRequirement(requirement1);
    final ValueRequirement requirement2 = new ValueRequirement("value2", target.toSpecification());
    fn2.addResult(new ValueSpecification(requirement2.getValueName(), target.toSpecification(), ValueProperties.with(ValuePropertyNames.FUNCTION, "fn2").get()), "result2");
    functionRepository.addFunction(fn2);

    env.setFunctionRepository(functionRepository);

    final ViewDefinition vd = new ViewDefinition(UniqueId.of("test", "vd1"), "Test view", UserPrincipal.getLocalUser());
    final ViewCalculationConfiguration calcConfig = new ViewCalculationConfiguration(vd, "Default");
    calcConfig.addSpecificRequirement(requirement2);
    vd.addViewCalculationConfiguration(calcConfig);
    vd.setMinFullCalculationPeriod(Long.MAX_VALUE); // Never force a full calculation
    vd.setMaxFullCalculationPeriod(Long.MAX_VALUE); // Never force a full calculation
    env.setViewDefinition(vd);

    env.init();

    final ViewProcessorImpl vp = env.getViewProcessor();
    vp.start();

    final ViewClient client = vp.createViewClient(ViewProcessorTestEnvironment.TEST_USER);
    final TestViewResultListener resultListener = new TestViewResultListener();
    client.setResultListener(resultListener);

    client.attachToViewProcess(env.getViewDefinition().getUniqueId(), ExecutionOptions.infinite(MarketData.live(), ExecutionFlags.none().get()));

    resultListener.assertViewDefinitionCompiled(TIMEOUT);
    final ViewComputationResultModel result1 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, resultListener.getQueueSize());

    assertEquals(1, result1.getAllResults().size());
    final ComputedValueResult result1Value = Iterables.getOnlyElement(result1.getAllResults()).getComputedValue();
    assertEquals("result2", result1Value.getValue());

    final AggregatedExecutionLog log1 = result1Value.getAggregatedExecutionLog();
    assertNotNull(log1);
    assertTrue(log1.getLogLevels().contains(LogLevel.ERROR));
    assertTrue(log1.getLogLevels().contains(LogLevel.WARN));
    assertFalse(log1.getLogLevels().contains(LogLevel.INFO));
    assertNull(log1.getLogs());

    final Pair<String, ValueSpecification> resultSpec = Pair.of(calcConfig.getName(), Iterables.getOnlyElement(client.getLatestCompiledViewDefinition().getTerminalValuesRequirements().keySet()));
    client.setMinimumLogMode(ExecutionLogMode.FULL, ImmutableSet.of(resultSpec));

    final ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
    final ViewProcessWorker worker = env.getCurrentWorker(viewProcess);
    worker.triggerCycle();

    final ViewComputationResultModel result2 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(0, resultListener.getQueueSize());
View Full Code Here

  /**
   * @throws java.lang.Exception
   */
  @BeforeMethod
  public void setUp() throws Exception {
    _env = new ViewProcessorTestEnvironment();
    _env.init();
    _mBeanServer = createMBeanServer();
    _statisticsProvider = new TotallingGraphStatisticsGathererProvider();
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.test.ViewProcessorTestEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.