@Override public ListenableFuture<NestedLoopJoinPages> getPagesFuture() { return transformAsync(pagesFuture, Futures::immediateFuture, directExecutor()); }
@Override public ListenableFuture<?> asyncCommit(TransactionId transactionId) { return nonCancellationPropagating(Futures.transformAsync(removeTransactionMetadataAsFuture(transactionId), TransactionMetadata::asyncCommit, directExecutor())); }
@Override public ListenableFuture<?> asyncAbort(TransactionId transactionId) { return nonCancellationPropagating(Futures.transformAsync(removeTransactionMetadataAsFuture(transactionId), TransactionMetadata::asyncAbort, directExecutor())); }
@Override protected ListenableFuture<String> buildChainingFuture(ListenableFuture<Integer> inputFuture) { outputFuture = SettableFuture.create(); funcIsWaitingLatch = new CountDownLatch(1); funcCompletionLatch = new CountDownLatch(1); return transformAsync(inputFuture, new ChainingFunction(), directExecutor()); }
@GwtIncompatible // get() timeout public void testTransformAsync_asyncFunction_timeout() throws InterruptedException, ExecutionException { AsyncFunction<String, Integer> function = constantAsyncFunction(immediateFuture(1)); ListenableFuture<Integer> future = transformAsync(SettableFuture.<String>create(), function, directExecutor()); try { future.get(1, MILLISECONDS); fail(); } catch (TimeoutException expected) { } }
public void testTransformAsync_ErrorAfterCancellation() throws Exception { class Transformer implements AsyncFunction<Object, Object> { ListenableFuture<Object> output; @Override public ListenableFuture<Object> apply(Object input) { output.cancel(false); throw new MyError(); } } Transformer transformer = new Transformer(); SettableFuture<Object> input = SettableFuture.create(); ListenableFuture<Object> output = transformAsync(input, transformer, directExecutor()); transformer.output = output; input.set("foo"); assertTrue(output.isCancelled()); }
public void testTransformAsync_ExceptionAfterCancellation() throws Exception { class Transformer implements AsyncFunction<Object, Object> { ListenableFuture<Object> output; @Override public ListenableFuture<Object> apply(Object input) { output.cancel(false); throw new MyRuntimeException(); } } Transformer transformer = new Transformer(); SettableFuture<Object> input = SettableFuture.create(); ListenableFuture<Object> output = transformAsync(input, transformer, directExecutor()); transformer.output = output; input.set("foo"); assertTrue(output.isCancelled()); }
public void testTransformAsync_genericsWildcard_AsyncFunction() throws Exception { ListenableFuture<?> nullFuture = immediateFuture(null); ListenableFuture<?> chainedFuture = transformAsync(nullFuture, constantAsyncFunction(nullFuture), directExecutor()); assertNull(getDone(chainedFuture)); }
public void testTransformAsync_listenerThrowsError() throws Exception { SettableFuture<Object> input = SettableFuture.create(); ListenableFuture<Object> output = transformAsync(input, asyncIdentity(), directExecutor()); output.addListener( new Runnable() { @Override public void run() { throw new MyError(); } }, directExecutor()); try { input.set("foo"); fail(); } catch (MyError expected) { } }
public void testTransformAsync_asyncFunction_error() throws InterruptedException { final Error error = new Error("deliberate"); AsyncFunction<String, Integer> function = new AsyncFunction<String, Integer>() { @Override public ListenableFuture<Integer> apply(String input) { throw error; } }; SettableFuture<String> inputFuture = SettableFuture.create(); ListenableFuture<Integer> outputFuture = transformAsync(inputFuture, function, directExecutor()); inputFuture.set("value"); try { getDone(outputFuture); fail(); } catch (ExecutionException expected) { assertSame(error, expected.getCause()); } }
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_genericsHierarchy_AsyncFunction() throws Exception { ListenableFuture<FooChild> future = immediateFuture(null); final BarChild barChild = new BarChild(); AsyncFunction<Foo, BarChild> function = new AsyncFunction<Foo, BarChild>() { @Override public AbstractFuture<BarChild> apply(Foo unused) { AbstractFuture<BarChild> future = new AbstractFuture<BarChild>() {}; future.set(barChild); return future; } }; Bar bar = getDone(transformAsync(future, function, directExecutor())); assertSame(barChild, bar); }
public void testTransformAsync_asyncFunction_nullInsteadOfFuture() throws Exception { ListenableFuture<?> inputFuture = immediateFuture("a"); ListenableFuture<?> chainedFuture = transformAsync(inputFuture, constantAsyncFunction(null), directExecutor()); try { getDone(chainedFuture); fail(); } catch (ExecutionException expected) { NullPointerException cause = (NullPointerException) expected.getCause(); assertThat(cause) .hasMessageThat() .contains( "AsyncFunction.apply returned null instead of a Future. " + "Did you mean to return immediateFuture(null)?"); } }
public void testTransformAsync_getThrowsRuntimeException() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingRuntimeException(new MyRuntimeException()); ListenableFuture<Object> output = transformAsync(input, asyncIdentity(), directExecutor()); try { getDone(output); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyRuntimeException.class); } }
public void testTransformAsync_getThrowsError() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingError(new MyError()); ListenableFuture<Object> output = transformAsync(input, asyncIdentity(), directExecutor()); try { getDone(output); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyError.class); } }
public void testTransformAsync_cancelPropagatesToInput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { throw new AssertionFailedError("Unexpeted call to apply."); } }; assertTrue(transformAsync(input, function, directExecutor()).cancel(false)); assertTrue(input.isCancelled()); assertFalse(input.wasInterrupted()); }
public void testTransformAsync_interruptPropagatesToInput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { throw new AssertionFailedError("Unexpeted call to apply."); } }; assertTrue(transformAsync(input, function, directExecutor()).cancel(true)); assertTrue(input.isCancelled()); assertTrue(input.wasInterrupted()); }
public void testTransformAsync_inputCancelButNotInterruptPropagatesToOutput() throws Exception { SettableFuture<Foo> f1 = SettableFuture.create(); final SettableFuture<Bar> secondary = SettableFuture.create(); AsyncFunction<Foo, Bar> function = new AsyncFunction<Foo, Bar>() { @Override public ListenableFuture<Bar> apply(Foo unused) { return secondary; } }; ListenableFuture<Bar> f2 = transformAsync(f1, function, directExecutor()); f1.cancel(true); assertTrue(f2.isCancelled()); /* * We might like to propagate interruption, too, but it's not clear that it matters. For now, we * test for the behavior that we have today. */ assertFalse(((AbstractFuture<?>) f2).wasInterrupted()); }
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 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()); }