//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(); } }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeOut = 5000) public void interruptHangingCalculate() throws InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void interruptHangingCalculate() { 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)); // 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); AtomicBoolean shouldNeverThrow = new AtomicBoolean(); AtomicBoolean interrupted = new AtomicBoolean(); AtomicReference <Results> results = new AtomicReference <Results>(); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); Thread thread = new Thread(() => { try { Results result = test.calculate(tasks, marketData, REF_DATA); interrupted.set(Thread.CurrentThread.Interrupted); results.set(result); } catch (Exception) { shouldNeverThrow.set(true); } 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(shouldNeverThrow.get(), false); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result00 = results.get().get(0, 0); Result <object> result00 = results.get().get(0, 0); assertEquals(result00.Failure, true); assertEquals(result00.Failure.Reason, FailureReason.CALCULATION_FAILED); assertEquals(result00.Failure.Message.Contains("Runtime interrupted"), true); }