Refine search
@Override protected boolean setException(Throwable throwable) { return super.setException(throwable); }
@Override public AbstractFuture<BarChild> apply(Foo unused) { AbstractFuture<BarChild> future = new AbstractFuture<BarChild>() {}; future.set(barChild); return future; } };
@CanIgnoreReturnValue @Override public final boolean cancel(boolean mayInterruptIfRunning) { return super.cancel(mayInterruptIfRunning); } }
/** * If this future has been cancelled (and possibly interrupted), cancels (and possibly interrupts) * the given future (if available). */ final void maybePropagateCancellationTo(@Nullable Future<?> related) { if (related != null & isCancelled()) { related.cancel(wasInterrupted()); } }
@Override public String toString() { StringBuilder builder = new StringBuilder().append(super.toString()).append("[status="); if (isCancelled()) { builder.append("CANCELLED"); } else if (isDone()) { addDoneString(builder); } else { String pendingDescription; try { pendingDescription = pendingToString(); } catch (RuntimeException e) { // Don't call getMessage or toString() on the exception, in case the exception thrown by the // subclass is implemented with bugs similar to the subclass. pendingDescription = "Exception thrown from implementation: " + e.getClass(); } // The future may complete during or before the call to getPendingToString, so we use null // as a signal that we should try checking if the future is done again. if (pendingDescription != null && !pendingDescription.isEmpty()) { builder.append("PENDING, info=[").append(pendingDescription).append("]"); } else if (isDone()) { addDoneString(builder); } else { builder.append("PENDING"); } } return builder.append("]").toString(); }
@CanIgnoreReturnValue @Override public final V get() throws InterruptedException, ExecutionException { return super.get(); }
@CanIgnoreReturnValue @Override public boolean setException(Throwable t) { return super.setException(t); } }
private static void assertCannotSet(AbstractFuture<Integer> future) { assertThat(future.set(99)).isFalse(); assertThat(future.setException(new IndexOutOfBoundsException())).isFalse(); assertThat(future.setFuture(new AbstractFuture<Integer>() {})).isFalse(); assertThat(future.setFuture(immediateFuture(99))).isFalse(); }
@CanIgnoreReturnValue @Override public boolean set(T t) { return super.set(t); }
@CanIgnoreReturnValue @Override public boolean cancel(boolean mayInterruptIfRunning) { abstractFuture.interruptTask(); complete(abstractFuture); if (localValue instanceof SetFuture) {
@Override public boolean cancel(boolean interruptIfRunning) { InCompletionOrderState<T> localState = state; if (super.cancel(interruptIfRunning)) { localState.recordOutputCancellation(interruptIfRunning); return true; } return false; }
@Override public void run() { future.setException(new IllegalArgumentException("failure")); if (!future.isDone()) { errorMessage.set("SetException call exited before future was complete."); } } });
public void testToString_completed() throws Exception { AbstractFuture<Object> testFuture2 = new AbstractFuture<Object>() { @Override public String pendingToString() { return "cause=[Someday...]"; } }; AbstractFuture<Object> testFuture3 = new AbstractFuture<Object>() {}; testFuture3.setFuture(testFuture2); assertThat(testFuture3.toString()) .matches( "[^\\[]+\\[status=PENDING, info=\\[setFuture=" + "\\[[^\\[]+\\[status=PENDING, info=\\[cause=\\[Someday...\\]\\]\\]\\]\\]\\]"); testFuture2.set("result string"); assertThat(testFuture3.toString()) .matches("[^\\[]+\\[status=SUCCESS, result=\\[result string\\]\\]"); }
public void testGetFailure_Failed() { AbstractFuture<String> future = new AbstractFuture<String>() {}; final Throwable failure = new Throwable(); future.setException(failure); assertThat(future.tryInternalFastPathGetFailure()).isNull(); }
public void testCancel_done() throws Exception { AbstractFuture<String> future = new AbstractFuture<String>() { { set("foo"); } }; assertFalse(future.cancel(true)); assertFalse(future.isCancelled()); assertTrue(future.isDone()); }
public void testGetFailure_Completed() { AbstractFuture<String> future = new AbstractFuture<String>() {}; future.set("261"); assertThat(future.tryInternalFastPathGetFailure()).isNull(); }
@Override public void run() { try { future.get(); } catch (Exception e) { // nothing } }