//------------------------------------------------------------------------- public Results calculateMultiScenario(CalculationTasks tasks, ScenarioMarketData marketData, ReferenceData refData) { ResultsListener listener = new ResultsListener(); calculateMultiScenarioAsync(tasks, marketData, refData, listener); return(listener.result()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeOut = 5000) public void interruptHangingResultsListener() throws InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void interruptHangingResultsListener() { HangingFunction fn = new HangingFunction(); 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)); ExecutorService executor = Executors.newSingleThreadExecutor(); try { CalculationTaskRunner test = CalculationTaskRunner.of(executor); MarketData marketData = MarketData.empty(VAL_DATE); AtomicBoolean shouldNeverComplete = new AtomicBoolean(); AtomicBoolean interrupted = new AtomicBoolean(); AtomicReference <Exception> thrown = new AtomicReference <Exception>(); ResultsListener listener = new ResultsListener(); test.calculateAsync(tasks, marketData, REF_DATA, listener); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); Thread thread = new Thread(() => { try { listener.result(); shouldNeverComplete.set(true); } catch (Exception ex) { interrupted.set(Thread.CurrentThread.Interrupted); thrown.set(ex); } latch.Signal(); }); // run the thread, wait until properly started, then interrupt, wait until properly handled thread.Start(); while (!fn.started) { } thread.Interrupt(); latch.await(); // asserts assertEquals(interrupted.get(), true); assertEquals(shouldNeverComplete.get(), false); assertEquals(thrown.get() is Exception, true); assertEquals(thrown.get().Cause is InterruptedException, true); } finally { executor.shutdownNow(); } }
//------------------------------------------------------------------------- // Test that ScenarioArrays containing a single value are unwrapped. //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void unwrapScenarioResults() throws Exception public virtual void unwrapScenarioResults() { 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()); MarketData marketData = MarketData.empty(VAL_DATE); Results results1 = test.calculate(tasks, marketData, REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result1 = results1.get(0, 0); Result <object> result1 = results1.get(0, 0); // Check the result contains the string directly, not the result wrapping the string assertThat(result1).hasValue("foo"); Results results2 = test.calculateMultiScenario(tasks, ScenarioMarketData.of(1, marketData), REF_DATA); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result2 = results2.get(0, 0); Result <object> result2 = results2.get(0, 0); // Check the result contains the scenario result wrapping the string assertThat(result2).hasValue(scenarioResult); ResultsListener resultsListener = new ResultsListener(); test.calculateAsync(tasks, marketData, REF_DATA, resultsListener); CompletableFuture <Results> future = resultsListener.Future; // The future is guaranteed to be done because everything is running on a single thread assertThat(future.Done).True; Results results3 = future.get(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result3 = results3.get(0, 0); Result <object> result3 = results3.get(0, 0); // Check the result contains the string directly, not the result wrapping the string assertThat(result3).hasValue("foo"); }