Package com.opengamma.engine.test

Examples of com.opengamma.engine.test.MockFunction


    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());

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

    final AggregatedExecutionLog log2 = result2Value.getAggregatedExecutionLog();
    assertNotNull(log2);
    assertTrue(log2.getLogLevels().contains(LogLevel.ERROR));
    assertTrue(log2.getLogLevels().contains(LogLevel.WARN));
    assertFalse(log2.getLogLevels().contains(LogLevel.INFO));
    assertNotNull(log2.getLogs());
    assertEquals(2, log2.getLogs().size());

    final ExecutionLogWithContext result2LogContext = log2.getLogs().get(0);
    assertNotNull(result2LogContext);
    assertEquals(fn2.getFunctionDefinition().getShortName(), result2LogContext.getFunctionName());
    assertEquals(resultSpec.getSecond().getTargetSpecification(), result2LogContext.getTargetSpecification());
    final ExecutionLog result2Log = result2LogContext.getExecutionLog();
    assertEquals(1, result2Log.getEvents().size());
    final LogEvent result2Event1 = result2Log.getEvents().get(0);
    assertEquals(LogLevel.WARN, result2Event1.getLevel());
View Full Code Here


  private final ComputationTargetSpecification _target;
  private final Set<ValueSpecification> _inputs;
  private final Set<ValueSpecification> _outputs;

  public DefaultManageableFunctionBlacklistTest() {
    _function = new ParameterizedFunction(new MockFunction("F1", null), new EmptyFunctionParameters());
    _target = ComputationTargetSpecification.of(UniqueId.of("Test", "Foo"));
    _inputs = Collections.singleton(new ValueSpecification("Foo", _target, ValueProperties.with(ValuePropertyNames.FUNCTION, "X").get()));
    _outputs = Collections.singleton(new ValueSpecification("Bar", _target, ValueProperties.with(ValuePropertyNames.FUNCTION, "Y").get()));
  }
View Full Code Here

TOP

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

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.