@Override
 protected String[][] getRawDataRows(ViewComputationResultModel result) {
   String[][] rows = new String[getGridStructure().getTargets().size()][];
   int columnCount = getGridStructure().getColumns().size() + getAdditionalCsvColumnCount();
   int offset = getCsvDataColumnOffset();
   for (ComputationTargetSpecification target : result.getAllTargets()) {
     Integer rowId = getGridStructure().getRowId(target);
     if (rowId == null) {
       continue;
     }
     ViewTargetResultModel resultModel = result.getTargetResult(target);
     String[] values = new String[columnCount];
     supplementCsvRowData(rowId, target, values);
     rows[rowId] = values;
     for (String calcConfigName : resultModel.getCalculationConfigurationNames()) {
       for (ComputedValue value : resultModel.getAllValues(calcConfigName)) {
         Object originalValue = value.getValue();
         if (originalValue == null) {
           continue;
         }
         ValueSpecification specification = value.getSpecification();
         Collection<WebViewGridColumn> columns =
             getGridStructure().getColumns(calcConfigName, specification);
         if (columns == null) {
           // Expect a column for every value
           s_logger.warn(
               "Could not find column for calculation configuration {} with value specification {}",
               calcConfigName,
               specification);
           continue;
         }
         for (WebViewGridColumn column : columns) {
           int colId = column.getId();
           ResultConverter<Object> converter =
               getConverter(
                   column, value.getSpecification().getValueName(), originalValue.getClass());
           values[offset + colId] =
               converter.convertToText(
                   getConverterCache(), value.getSpecification(), originalValue);
         }
       }
     }
   }
   return rows;
 }
Example #2
0
  @Test
  public void testComputationResultsFlow() throws InterruptedException {
    ViewProcessorTestEnvironment env = new ViewProcessorTestEnvironment();
    SynchronousInMemoryLKVSnapshotProvider marketDataProvider =
        new SynchronousInMemoryLKVSnapshotProvider();
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 0);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 0);
    env.setMarketDataProvider(marketDataProvider);
    env.init();

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

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

    // Client not attached - should not have been listening to anything that might have been going
    // on
    assertEquals(0, resultListener.getQueueSize());

    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 1);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 2);

    assertEquals(0, resultListener.getQueueSize());

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

    ViewProcessImpl viewProcess = env.getViewProcess(vp, client.getUniqueId());
    assertTrue(viewProcess.getState() == ViewProcessState.RUNNING);

    resultListener.assertViewDefinitionCompiled(TIMEOUT);
    resultListener.assertCycleStarted(TIMEOUT);
    ViewResultModel result1Fragment =
        resultListener.getCycleFragmentCompleted(TIMEOUT).getFullFragment();
    assertNotNull(result1Fragment);
    ViewComputationResultModel result1 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertNotNull(result1);

    Map<ValueRequirement, Object> expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 1);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 2);
    assertComputationResult(expected, env.getCalculationResult(result1));
    assertComputationResult(expected, env.getCalculationResult(result1Fragment));
    assertTrue(client.isResultAvailable());
    assertEquals(result1, client.getLatestResult());

    client.pause();

    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    marketDataProvider.addValue(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 4);

    env.getCurrentComputationJob(viewProcess)
        .marketDataChanged(); // Need to get it to perform another cycle

    // Should have been merging results received in the meantime
    client.resume();
    UniqueId cycleStartedId =
        resultListener.getCycleStarted(TIMEOUT).getCycleMetadata().getViewCycleId();
    resultListener.assertCycleFragmentCompleted(TIMEOUT);
    ViewComputationResultModel result2 = resultListener.getCycleCompleted(TIMEOUT).getFullResult();
    assertEquals(result2.getViewCycleId(), cycleStartedId);

    expected = new HashMap<ValueRequirement, Object>();
    expected.put(ViewProcessorTestEnvironment.getPrimitive1(), (byte) 3);
    expected.put(ViewProcessorTestEnvironment.getPrimitive2(), (byte) 4);
    assertComputationResult(expected, env.getCalculationResult(result2));
  }