@CanIgnoreReturnValue @Override public final V get() throws InterruptedException, ExecutionException { return super.get(); }
@CanIgnoreReturnValue @Override public final V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return super.get(timeout, unit); }
@Override public void run() { try { future.get(); } catch (Exception e) { // nothing } }
@Override public List<Message> get() { while (true) { try { return super.get(); } catch (InterruptedException e) { LOGGER.info("ignore interrupt pull"); } catch (ExecutionException e) { return Collections.emptyList(); } } }
@CanIgnoreReturnValue @Override public final V get() throws InterruptedException, ExecutionException { return super.get(); }
@Override public void run() { while (true) { try { future.get(0, TimeUnit.SECONDS); return; } catch (InterruptedException | ExecutionException e) { return; } catch (TimeoutException e) { // do nothing } finally { completedIteration.countDown(); } } }
@CanIgnoreReturnValue @Override public final V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return super.get(timeout, unit); }
@Override public void run() { startTime = System.nanoTime(); try { future.get(timeout, unit); } catch (Exception e) { // nothing exception = e; } finally { timeSpentBlocked = System.nanoTime() - startTime; } }
@CanIgnoreReturnValue @Override public final V get() throws InterruptedException, ExecutionException { return super.get(); }
@CanIgnoreReturnValue @Override public final V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return super.get(timeout, unit); }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException { callAsyncGet(timeout, unit); return super.get(0, TimeUnit.MILLISECONDS); }
@Override public T get() throws InterruptedException, ExecutionException { callAsyncGet(-1, TimeUnit.MILLISECONDS); return super.get(); }
@Override public V get() throws ExecutionException, InterruptedException { try { super.get(); } catch (ExecutionException e) { rethrow(e); } throw new AssertionError("Unreachable"); }
private ExecutionException getExpectingExecutionException(AbstractFuture<String> future) throws InterruptedException { try { String got = future.get(); fail("Expected exception but got " + got); } catch (ExecutionException e) { return e; } // unreachable, but compiler doesn't know that fail() always throws return null; }
@Override public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { super.get(timeout, unit); } catch (ExecutionException e) { rethrow(e); } throw new AssertionError("Unreachable"); } }
public void testGetWithTimeoutDoneFuture() throws Exception { AbstractFuture<String> future = new AbstractFuture<String>() { { set("foo"); } }; assertEquals("foo", future.get(0, TimeUnit.SECONDS)); }
f.get(); final AtomicBoolean ranImmediately = new AtomicBoolean(); f.addListener(
future.get(); } catch (Throwable t) {
public void testEvilFuture_setFuture() throws Exception { final RuntimeException exception = new RuntimeException("you didn't say the magic word!"); AbstractFuture<String> evilFuture = new AbstractFuture<String>() { @Override public void addListener(Runnable r, Executor e) { throw exception; } }; AbstractFuture<String> normalFuture = new AbstractFuture<String>() {}; normalFuture.setFuture(evilFuture); assertTrue(normalFuture.isDone()); try { normalFuture.get(); fail(); } catch (ExecutionException e) { assertThat(e).hasCauseThat().isSameAs(exception); } }
public void testToString_notDone() throws Exception { AbstractFuture<Object> testFuture = new AbstractFuture<Object>() { @Override public String pendingToString() { return "cause=[Because this test isn't done]"; } }; assertThat(testFuture.toString()) .matches( "[^\\[]+\\[status=PENDING, info=\\[cause=\\[Because this test isn't done\\]\\]\\]"); try { testFuture.get(1, TimeUnit.NANOSECONDS); fail(); } catch (TimeoutException e) { assertThat(e.getMessage()).contains("1 nanoseconds"); assertThat(e.getMessage()).contains("Because this test isn't done"); } }