// 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)); }
/// <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)); }