public void setResultFuture(ListenableFuture<byte[]> f) { resultFuture.setFuture(f); }
@Override public void run() { if (taskFuture.isDone() // If this CAS succeeds, we know that the provided callable will never be invoked, // so when oldFuture completes it is safe to allow the next submitted task to // proceed. || (outputFuture.isCancelled() && runningState.compareAndSet(NOT_RUN, CANCELLED))) { // Since the value of oldFuture can only ever be immediateFuture(null) or setFuture of // a future that eventually came from immediateFuture(null), this doesn't leak // throwables or completion values. newFuture.setFuture(oldFuture); } } };
public void testSetFuture_stackOverflow() { SettableFuture<String> orig = SettableFuture.create(); SettableFuture<String> prev = orig; for (int i = 0; i < 100000; i++) { SettableFuture<String> curr = SettableFuture.create(); prev.setFuture(curr); prev = curr; } // prev represents the 'innermost' future prev.set("done"); assertTrue(orig.isDone()); }
public void testSetFutureSelf_toString() { SettableFuture<String> orig = SettableFuture.create(); orig.setFuture(orig); assertThat(orig.toString()).contains("[status=PENDING, info=[setFuture=[this future]]]"); }
public void testSetFutureSelf_cancel() { SettableFuture<String> orig = SettableFuture.create(); orig.setFuture(orig); orig.cancel(true); assertTrue(orig.isCancelled()); }
future.setFuture(badFuture); assertThat(future.isCancelled()).isTrue();
public void testCancel_innerCancelsAsync() throws Exception { SettableFuture<Object> async = SettableFuture.create(); SettableFuture<Object> inner = SettableFuture.create(); async.setFuture(inner); inner.cancel(true); assertTrue(async.isCancelled()); try { async.get(); fail("Expected CancellationException"); } catch (CancellationException expected) { /* expected */ } }
public void testSetValue_simpleThreaded() throws Exception { SettableFuture<Integer> future = SettableFuture.create(); assertTrue(future.set(42)); // Later attempts to set the future should return false. assertFalse(future.set(23)); assertFalse(future.setException(new Exception("bar"))); assertFalse(future.setFuture(SettableFuture.<Integer>create())); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals(42, (int) future.get()); }
public void testSetException() throws Exception { SettableFuture<Object> future = SettableFuture.create(); Exception e = new Exception("foobarbaz"); assertTrue(future.setException(e)); // Later attempts to set the future should return false. assertFalse(future.set(23)); assertFalse(future.setException(new Exception("quux"))); assertFalse(future.setFuture(SettableFuture.create())); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException ee) { assertThat(ee).hasCauseThat().isSameAs(e); } }
public void testCancel_multipleBeforeSetFuture_interruptFirst() throws Exception { SettableFuture<Object> async = SettableFuture.create(); async.cancel(true); async.cancel(false); SettableFuture<Object> inner = SettableFuture.create(); assertFalse(async.setFuture(inner)); assertTrue(inner.isCancelled()); assertTrue(inner.wasInterrupted()); } }
public void testCancel_multipleBeforeSetFuture_noInterruptFirst() throws Exception { SettableFuture<Object> async = SettableFuture.create(); async.cancel(false); async.cancel(true); SettableFuture<Object> inner = SettableFuture.create(); assertFalse(async.setFuture(inner)); assertTrue(inner.isCancelled()); assertFalse(inner.wasInterrupted()); }
public void testCancel_stackOverflow() { SettableFuture<String> orig = SettableFuture.create(); SettableFuture<String> prev = orig; for (int i = 0; i < 100000; i++) { SettableFuture<String> curr = SettableFuture.create(); prev.setFuture(curr); prev = curr; } // orig is the 'outermost future', this should propagate fully down the stack of futures. orig.cancel(true); assertTrue(orig.isCancelled()); assertTrue(prev.isCancelled()); assertTrue(prev.wasInterrupted()); }
public void testCancel_resultCancelsInner() throws Exception { SettableFuture<Object> async = SettableFuture.create(); SettableFuture<Object> inner = SettableFuture.create(); async.setFuture(inner); async.cancel(false); assertTrue(inner.isCancelled()); assertFalse(inner.wasInterrupted()); try { inner.get(); fail("Expected CancellationException"); } catch (CancellationException expected) { /* expected */ } }
public void testCancel_resultCancelsInner_interrupted() throws Exception { SettableFuture<Object> async = SettableFuture.create(); SettableFuture<Object> inner = SettableFuture.create(); async.setFuture(inner); async.cancel(true); assertTrue(inner.isCancelled()); assertTrue(inner.wasInterrupted()); try { inner.get(); fail("Expected CancellationException"); } catch (CancellationException expected) { /* expected */ } }
future.setFuture(badFuture); ExecutionException expected = getExpectingExecutionException(future); assertThat(expected).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
public void testSetFuture() throws Exception { SettableFuture<String> future = SettableFuture.create(); SettableFuture<String> nested = SettableFuture.create(); assertTrue(future.setFuture(nested)); // Later attempts to set the future should return false. assertFalse(future.set("x")); assertFalse(future.setException(new Exception("bar"))); assertFalse(future.setFuture(SettableFuture.<String>create())); // Check that the future has been set properly. assertFalse(future.isDone()); assertFalse(future.isCancelled()); try { future.get(0, TimeUnit.MILLISECONDS); fail("Expected TimeoutException"); } catch (TimeoutException expected) { /* expected */ } nested.set("foo"); assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals("foo", future.get()); }
normalFuture.setFuture(new FailFuture(exception)); assertTrue(normalFuture.isDone()); try {
public void testSetFuture_genericsHierarchy() throws Exception { SettableFuture<Foo> future = SettableFuture.create(); SettableFuture<FooChild> nested = SettableFuture.create(); assertTrue(future.setFuture(nested)); // Later attempts to set the future should return false. assertFalse(future.set(new Foo())); assertFalse(future.setException(new Exception("bar"))); assertFalse(future.setFuture(SettableFuture.<Foo>create())); // Check that the future has been set properly. assertFalse(future.isDone()); assertFalse(future.isCancelled()); try { future.get(0, TimeUnit.MILLISECONDS); fail("Expected TimeoutException"); } catch (TimeoutException expected) { /* expected */ } FooChild value = new FooChild(); nested.set(value); assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertSame(value, future.get()); }
@Override public void run() { delegates.remove().setFuture(future); } }, executor);
public void testCancel_multipleBeforeSetFuture_interruptFirst() throws Exception { SettableFuture<Object> async = SettableFuture.create(); async.cancel(true); async.cancel(false); SettableFuture<Object> inner = SettableFuture.create(); assertFalse(async.setFuture(inner)); assertTrue(inner.isCancelled()); assertTrue(inner.wasInterrupted()); } }