/// <summary>
        /// Test that ScenarioArrays containing a single value are unwrapped when calling calculateAsync().
        /// </summary>
        public virtual void unwrapScenarioResultsAsync()
        {
            ScenarioArray <string> scenarioResult = ScenarioArray.of("foo");
            ScenarioResultFunction fn             = new ScenarioResultFunction(TestingMeasures.PRESENT_VALUE, scenarioResult);
            CalculationTaskCell    cell           = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, NATURAL);
            CalculationTask        task           = CalculationTask.of(TARGET, fn, cell);
            Column           column = Column.of(TestingMeasures.PRESENT_VALUE);
            CalculationTasks tasks  = CalculationTasks.of(ImmutableList.of(task), ImmutableList.of(column));

            // using the direct executor means there is no need to close/shutdown the runner
            CalculationTaskRunner test = CalculationTaskRunner.of(MoreExecutors.newDirectExecutorService());
            Listener listener          = new Listener();

            MarketData marketData = MarketData.empty(VAL_DATE);

            test.calculateAsync(tasks, marketData, REF_DATA, listener);
            CalculationResult calculationResult1 = listener.result;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result1 = calculationResult1.getResult();
            Result <object> result1 = calculationResult1.Result;

            // Check the result contains the string directly, not the result wrapping the string
            assertThat(result1).hasValue("foo");

            test.calculateMultiScenarioAsync(tasks, ScenarioMarketData.of(1, marketData), REF_DATA, listener);
            CalculationResult calculationResult2 = listener.result;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result2 = calculationResult2.getResult();
            Result <object> result2 = calculationResult2.Result;

            // Check the result contains the scenario result wrapping the string
            assertThat(result2).hasValue(scenarioResult);
        }
Ejemplo n.º 2
0
        // Tests that a listener is only invoked by a single thread at any time even if multiple threads are
        // invoking the wrapper concurrently.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void concurrentExecution() throws InterruptedException
        public virtual void concurrentExecution()
        {
            int nThreads         = Runtime.Runtime.availableProcessors();
            int resultsPerThread = 10;
            ConcurrentLinkedQueue <string> errors = new ConcurrentLinkedQueue <string>();

            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
            int      expectedResultCount          = nThreads * resultsPerThread;
            Listener listener = new Listener(errors, latch);

            System.Action <CalculationResults> wrapper = new ListenerWrapper(listener, expectedResultCount, ImmutableList.of(), ImmutableList.of());
            ExecutorService    executor = Executors.newFixedThreadPool(nThreads);
            CalculationResult  result   = CalculationResult.of(0, 0, Result.failure(FailureReason.ERROR, "foo"));
            CalculationTarget  target   = new CalculationTargetAnonymousInnerClass(this);
            CalculationResults results  = CalculationResults.of(target, ImmutableList.of(result));

            IntStream.range(0, expectedResultCount).forEach(i => executor.submit(() => wrapper(results)));

            latch.await();
            executor.shutdown();

            if (!errors.Empty)
            {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                string allErrors = errors.collect(joining("\n"));
                fail(allErrors);
            }
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            CalculationResult test = CalculationResult.of(1, 2, RESULT);

            coverImmutableBean(test);
            CalculationResult test2 = CalculationResult.of(0, 3, RESULT2);

            coverBeanEquals(test, test2);
            assertNotNull(CalculationResult.meta());
        }
        public virtual void of_failure()
        {
            CalculationResult test = CalculationResult.of(1, 2, FAILURE);

            assertEquals(test.RowIndex, 1);
            assertEquals(test.ColumnIndex, 2);
            assertEquals(test.Result, FAILURE);
            assertEquals(test.getResult(typeof(string)), FAILURE);
            assertEquals(test.getResult(typeof(Integer)), FAILURE);     // cannot throw exception as generic type not known
        }
        //-------------------------------------------------------------------------
        public virtual void of()
        {
            CalculationResult test = CalculationResult.of(1, 2, RESULT);

            assertEquals(test.RowIndex, 1);
            assertEquals(test.ColumnIndex, 2);
            assertEquals(test.Result, RESULT);
            assertEquals(test.getResult(typeof(string)), RESULT);
            assertThrows(() => test.getResult(typeof(Integer)), typeof(System.InvalidCastException));
        }
Ejemplo n.º 6
0
            public void resultReceived(CalculationTarget target, CalculationResult calculationResult)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResult.getResult();
                Result <object> result = calculationResult.Result;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> unwrappedResult = unwrapScenarioResult(result);
                Result <object>   unwrappedResult            = unwrapScenarioResult(result);
                CalculationResult unwrappedCalculationResult = calculationResult.withResult(unwrappedResult);

                @delegate.resultReceived(target, unwrappedCalculationResult);
            }
        /// <summary>
        /// Creates the result from the map of calculated measures.
        /// <para>
        /// This extracts the calculated measure and performs currency conversion if necessary.
        ///
        /// </para>
        /// </summary>
        /// <param name="task">  the calculation task </param>
        /// <param name="target">  the target of the calculation </param>
        /// <param name="results">  the map of result by measure </param>
        /// <param name="fxProvider">  the market data </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the calculation result </returns>
        internal CalculationResult createResult <T1>(CalculationTask task, CalculationTarget target, IDictionary <T1> results, ScenarioFxRateProvider fxProvider, ReferenceData refData)
        {
            // caller expects that this method does not throw an exception
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> calculated = results.get(measure);
            Result <object> calculated = results[measure];

            if (calculated == null)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                calculated = Result.failure(FailureReason.CALCULATION_FAILED, "Measure '{}' was not calculated by the function for target type '{}'", measure, target.GetType().FullName);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = convertCurrencyIfNecessary(task, calculated, fxProvider, refData);
            Result <object> result = convertCurrencyIfNecessary(task, calculated, fxProvider, refData);

            return(CalculationResult.of(rowIndex, columnIndex, result));
        }
Ejemplo n.º 8
0
            public void resultReceived(CalculationTarget target, CalculationResult result)
            {
                if (!string.ReferenceEquals(threadName, null))
                {
                    errors.AddLast("Expected threadName to be null but it was " + threadName);
                }
                threadName = Thread.CurrentThread.Name;

                try
                {
                    // Give other threads a chance to get into this method
                    Thread.Sleep(5);
                }
                catch (InterruptedException)
                {
                    // Won't ever happen
                }
                threadName = null;
            }
 public void resultReceived(CalculationTarget target, CalculationResult result)
 {
     this.result = result;
 }
Ejemplo n.º 10
0
 public override abstract void resultReceived(CalculationTarget target, CalculationResult result);
Ejemplo n.º 11
0
 public override void resultReceived(CalculationTarget target, CalculationResult result)
 {
     results.Add(result);
 }