public void testCancellationNotPropagatedIfAlreadyStarted() { serializer.submitAsync(firstCallable, directExecutor()).cancel(true); assertThat(firstFuture.isCancelled()).isFalse(); }
public void testSetFutureSelf_cancel() { SettableFuture<String> orig = SettableFuture.create(); orig.setFuture(orig); orig.cancel(true); assertTrue(orig.isCancelled()); }
/** Tests the initial state of the future. */ public void testCreate() throws Exception { SettableFuture<Integer> future = SettableFuture.create(); assertFalse(future.isDone()); assertFalse(future.isCancelled()); }
public void testAllAsList_resultCancelled_withSecondaryListFuture() throws Exception { SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); ListenableFuture<List<String>> compound = allAsList(future1, future2); // This next call is "unused," but it is an important part of the test. Don't remove it! ListenableFuture<List<String>> unused = allAsList(future1, future2); assertTrue(compound.cancel(false)); assertTrue(future1.isCancelled()); assertFalse(future1.wasInterrupted()); assertTrue(future2.isCancelled()); assertFalse(future2.wasInterrupted()); }
public void testFutureCancelAfterCompletion() throws Exception { inputFuture.set(VALID_INPUT_DATA); assertFalse(resultFuture.cancel(true)); assertFalse(resultFuture.isCancelled()); assertFalse(inputFuture.isCancelled()); assertFalse(outputFuture.isCancelled()); assertEquals(RESULT_DATA, resultFuture.get()); }
public void testFutureCancellableBeforeOutputCompletion() throws Exception { inputFuture.set(SLOW_OUTPUT_VALID_INPUT_DATA); assertTrue(resultFuture.cancel(true)); assertTrue(resultFuture.isCancelled()); assertFalse(inputFuture.isCancelled()); assertTrue(outputFuture.isCancelled()); try { resultFuture.get(); fail("Result future is cancelled and should have thrown a" + " CancellationException"); } catch (CancellationException expected) { } }
public void testFutureCancelBeforeInputCompletion() throws Exception { assertTrue(resultFuture.cancel(true)); assertTrue(resultFuture.isCancelled()); assertTrue(inputFuture.isCancelled()); assertFalse(outputFuture.isCancelled()); try { resultFuture.get(); fail("Result future is cancelled and should have thrown a" + " CancellationException"); } catch (CancellationException expected) { } }
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 testCatching_resultInterruptedBeforeFallback() throws Exception { SettableFuture<Integer> primary = SettableFuture.create(); Function<Throwable, Integer> fallback = unexpectedFunction(); ListenableFuture<Integer> derived = catching(primary, Throwable.class, fallback, directExecutor()); derived.cancel(true); assertTrue(primary.isCancelled()); assertTrue(primary.wasInterrupted()); }
public void testCatching_resultCancelledBeforeFallback() throws Exception { SettableFuture<Integer> primary = SettableFuture.create(); Function<Throwable, Integer> fallback = unexpectedFunction(); ListenableFuture<Integer> derived = catching(primary, Throwable.class, fallback, directExecutor()); derived.cancel(false); assertTrue(primary.isCancelled()); assertFalse(primary.wasInterrupted()); }
public void testCatchingAsync_resultInterruptedBeforeFallback() throws Exception { SettableFuture<Integer> primary = SettableFuture.create(); AsyncFunction<Throwable, Integer> fallback = unexpectedAsyncFunction(); ListenableFuture<Integer> derived = catchingAsync(primary, Throwable.class, fallback, directExecutor()); derived.cancel(true); assertTrue(primary.isCancelled()); assertTrue(primary.wasInterrupted()); }
public void testCatchingAsync_resultCancelledBeforeFallback() throws Exception { SettableFuture<Integer> primary = SettableFuture.create(); AsyncFunction<Throwable, Integer> fallback = unexpectedAsyncFunction(); ListenableFuture<Integer> derived = catchingAsync(primary, Throwable.class, fallback, directExecutor()); derived.cancel(false); assertTrue(primary.isCancelled()); assertFalse(primary.wasInterrupted()); }
public void testAllAsList_resultInterrupted() throws Exception { SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); @SuppressWarnings("unchecked") // array is never modified ListenableFuture<List<String>> compound = allAsList(future1, future2); future2.set(DATA2); assertFalse(compound.isDone()); assertTrue(compound.cancel(true)); assertTrue(compound.isCancelled()); assertTrue(future1.isCancelled()); assertTrue(future1.wasInterrupted()); }
public void testAllAsList_resultCancelled() throws Exception { SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); @SuppressWarnings("unchecked") // array is never modified ListenableFuture<List<String>> compound = allAsList(future1, future2); future2.set(DATA2); assertFalse(compound.isDone()); assertTrue(compound.cancel(false)); assertTrue(compound.isCancelled()); assertTrue(future1.isCancelled()); assertFalse(future1.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_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 testSuccessfulAsList_resultCancelled() throws Exception { SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); @SuppressWarnings("unchecked") // array is never modified ListenableFuture<List<String>> compound = successfulAsList(future1, future2); future2.set(DATA2); assertFalse(compound.isDone()); assertTrue(compound.cancel(false)); assertTrue(compound.isCancelled()); assertTrue(future1.isCancelled()); assertFalse(future1.wasInterrupted()); }
public void testSuccessfulAsList_resultInterrupted() throws Exception { SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); @SuppressWarnings("unchecked") // array is never modified ListenableFuture<List<String>> compound = successfulAsList(future1, future2); future2.set(DATA2); assertFalse(compound.isDone()); assertTrue(compound.cancel(true)); assertTrue(compound.isCancelled()); assertTrue(future1.isCancelled()); assertTrue(future1.wasInterrupted()); }
public void testNonCancellationPropagating_doesNotPropagate() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); ListenableFuture<Foo> wrapper = nonCancellationPropagating(input); assertTrue(wrapper.cancel(true)); assertTrue(wrapper.isCancelled()); assertTrue(wrapper.isDone()); assertFalse(input.isCancelled()); assertFalse(input.isDone()); }