public void testTransform_rejectionPropagatesToOutput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); Function<Foo, Foo> identity = identity(); ListenableFuture<Foo> transformed = transform(input, identity, REJECTING_EXECUTOR); input.set(new Foo()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
public void testTransformAsync_rejectionPropagatesToOutput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); AsyncFunction<Foo, Foo> asyncIdentity = asyncIdentity(); ListenableFuture<Foo> transformed = transformAsync(input, asyncIdentity, REJECTING_EXECUTOR); input.set(new Foo()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
public void testTransformAsync_interruptPropagatesToAsyncOutput() throws Exception { ListenableFuture<Foo> immediate = immediateFuture(new Foo()); final SettableFuture<Bar> secondary = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { return secondary; } }; assertTrue(transformAsync(immediate, function, directExecutor()).cancel(true)); assertTrue(secondary.isCancelled()); assertTrue(secondary.wasInterrupted()); }
public void testTransformAsync_interruptPropagatesToAsyncOutput() throws Exception { ListenableFuture<Foo> immediate = immediateFuture(new Foo()); final SettableFuture<Bar> secondary = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { return secondary; } }; assertTrue(transformAsync(immediate, function, directExecutor()).cancel(true)); assertTrue(secondary.isCancelled()); assertTrue(secondary.wasInterrupted()); }
public void testTransformAsync_rejectionPropagatesToOutput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); AsyncFunction<Foo, Foo> asyncIdentity = asyncIdentity(); ListenableFuture<Foo> transformed = transformAsync(input, asyncIdentity, REJECTING_EXECUTOR); input.set(new Foo()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
public void testTransform_rejectionPropagatesToOutput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); Function<Foo, Foo> identity = identity(); ListenableFuture<Foo> transformed = transform(input, identity, REJECTING_EXECUTOR); input.set(new Foo()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
public void testTransformAsync_cancelPropagatesToAsyncOutput() throws Exception { ListenableFuture<Foo> immediate = immediateFuture(new Foo()); final SettableFuture<Bar> secondary = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { return secondary; } }; assertTrue(transformAsync(immediate, function, directExecutor()).cancel(false)); assertTrue(secondary.isCancelled()); assertFalse(secondary.wasInterrupted()); }
public void testNonCancellationPropagating_successful() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); ListenableFuture<Foo> wrapper = nonCancellationPropagating(input); Foo foo = new Foo(); assertFalse(wrapper.isDone()); input.set(foo); assertTrue(wrapper.isDone()); assertSame(foo, getDone(wrapper)); }
public void testTransformAsync_cancelPropagatesToAsyncOutput() throws Exception { ListenableFuture<Foo> immediate = immediateFuture(new Foo()); final SettableFuture<Bar> secondary = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { return secondary; } }; assertTrue(transformAsync(immediate, function, directExecutor()).cancel(false)); assertTrue(secondary.isCancelled()); assertFalse(secondary.wasInterrupted()); }
public void testNonCancellationPropagating_successful() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); ListenableFuture<Foo> wrapper = nonCancellationPropagating(input); Foo foo = new Foo(); assertFalse(wrapper.isDone()); input.set(foo); assertTrue(wrapper.isDone()); assertSame(foo, getDone(wrapper)); }