@Test public void callableNotRunIfFutureAlreadyDone() { Callable<String> callable = mock(Callable.class); task = TaskFactory.createTask(callable, promise); when(future.isDone()).thenReturn(true); task.run(); verify(promise).future(); verifyNoMoreInteractions(promise); verifyZeroInteractions(callable); }
@Override public void run() { try { int state = this.state.get(); if (state == PENDING && !promise.future().isDone()) { runner = Thread.currentThread(); T result = callable.call(); safeSetSuccess(result); } else if (state == INTERRUPTING) { waitForInterruption(); } } catch (InterruptedException e) { } catch (Throwable e) { safeSetErred(e); } finally { Thread.interrupted(); } }
CancellableTask implements Runnable, Cancellable { @Override public void run() { try { int state = this.state.get(); if (state == PENDING && !promise.future().isDone()) { runner = Thread.currentThread(); T result = callable.call(); safeSetSuccess(result); } else if (state == INTERRUPTING) { waitForInterruption(); } } catch (InterruptedException e) { } catch (Throwable e) { safeSetErred(e); } finally { Thread.interrupted(); } } }
CancellableTask implements Runnable, Cancellable { @Override public void run() { try { int state = this.state.get(); if (state == PENDING && !promise.future().isDone()) { runner = Thread.currentThread(); T result = callable.call(); safeSetSuccess(result); } else if (state == INTERRUPTING) { waitForInterruption(); } } catch (InterruptedException e) { } catch (Throwable e) { safeSetErred(e); } finally { Thread.interrupted(); } } CancellableTask(ResultToStatus<Status, T> resultToStatus, ThrowableToStatus<Status> throwableToStatus,
                           Callable<T> callable, PrecipicePromise<Status, T> promise); }
CancellableTask implements Runnable, Cancellable { @Override public void run() { try { int state = this.state.get(); if (state == PENDING && !promise.future().isDone()) { runner = Thread.currentThread(); T result = callable.call(); safeSetSuccess(result); } else if (state == INTERRUPTING) { waitForInterruption(); } } catch (InterruptedException e) { } catch (Throwable e) { safeSetErred(e); } finally { Thread.interrupted(); } } CancellableTask(ResultToStatus<Status, T> resultToStatus, ThrowableToStatus<Status> throwableToStatus,
                           Callable<T> callable, PrecipicePromise<Status, T> promise); @Override void run(); @Override void cancel(); void cancel(Status cancelledStatus, Exception exception); }
CancellableTask implements Runnable, Cancellable { @Override public void run() { try { int state = this.state.get(); if (state == PENDING && !promise.future().isDone()) { runner = Thread.currentThread(); T result = callable.call(); safeSetSuccess(result); } else if (state == INTERRUPTING) { waitForInterruption(); } } catch (InterruptedException e) { } catch (Throwable e) { safeSetErred(e); } finally { Thread.interrupted(); } } CancellableTask(ResultToStatus<Status, T> resultToStatus, ThrowableToStatus<Status> throwableToStatus,
                           Callable<T> callable, PrecipicePromise<Status, T> promise); @Override void run(); @Override void cancel(); void cancel(Status cancelledStatus, Exception exception);  }