public virtual void test_poll_exception() { AtomicInteger counter = new AtomicInteger(); System.Func <string> pollingFn = () => { switch (counter.incrementAndGet()) { case 1: return(null); case 2: throw new System.InvalidOperationException("Expected"); default: throw new AssertionError("Test failed"); } }; ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { CompletableFuture <string> future = Guavate.poll(executor, Duration.ofMillis(100), Duration.ofMillis(100), pollingFn); assertThrows(() => future.join(), typeof(CompletionException), "java.lang.IllegalStateException: Expected"); } finally { executor.shutdown(); } }
internal virtual Resource StartPrinting() { ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.ScheduledFuture<?> timerFuture = timer.scheduleAtFixedRate(this::printOnNextUpdate, 0, interactive ? 100 : 5_000, java.util.concurrent.TimeUnit.MILLISECONDS); ScheduledFuture <object> timerFuture = timer.scheduleAtFixedRate(this.printOnNextUpdate, 0, _interactive ? 100 : 5_000, TimeUnit.MILLISECONDS); return(() => { timerFuture.cancel(false); timer.shutdown(); try { timer.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException) { } Done(); PrintProgress(); }); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void shutdown() throws LifeCycleException public override void shutdown() { base.shutdown(); scheduledService.shutdown(); }