public void testWhenAllComplete_wildcard() throws Exception { ListenableFuture<?> futureA = immediateFuture("a"); ListenableFuture<?> futureB = immediateFuture("b"); ListenableFuture<?>[] futures = new ListenableFuture<?>[0]; Callable<String> combiner = new Callable<String>() { @Override public String call() throws Exception { return "hi"; } }; // We'd like for all the following to compile. ListenableFuture<String> unused; // Compiles: unused = whenAllComplete(futureA, futureB).call(combiner, directExecutor()); // Does not compile: // unused = whenAllComplete(futures).call(combiner); // Workaround for the above: unused = whenAllComplete(asList(futures)).call(combiner, directExecutor()); }
@GwtIncompatible // threads public void testWhenAllComplete_noLeakInterruption() throws Exception { final SettableFuture<String> stringFuture = SettableFuture.create(); AsyncCallable<String> combiner = new AsyncCallable<String>() { @Override public ListenableFuture<String> call() throws Exception { return stringFuture; } }; ListenableFuture<String> futureResult = whenAllComplete().callAsync(combiner, directExecutor()); assertThat(Thread.interrupted()).isFalse(); futureResult.cancel(true); assertThat(Thread.interrupted()).isFalse(); }
public void testWhenAllComplete_runnableResult() throws Exception { final SettableFuture<Integer> futureInteger = SettableFuture.create(); final SettableFuture<Boolean> futureBoolean = SettableFuture.create(); final String[] result = new String[1]; Runnable combiner = new Runnable() { @Override public void run() { assertTrue(futureInteger.isDone()); assertTrue(futureBoolean.isDone()); result[0] = createCombinedResult( Futures.getUnchecked(futureInteger), Futures.getUnchecked(futureBoolean)); } }; ListenableFuture<?> futureResult = whenAllComplete(futureInteger, futureBoolean).run(combiner, directExecutor()); Integer integerPartial = 1; futureInteger.set(integerPartial); Boolean booleanPartial = true; futureBoolean.set(booleanPartial); futureResult.get(); assertEquals(createCombinedResult(integerPartial, booleanPartial), result[0]); }
public void testWhenAllComplete_runnableError() throws Exception { final RuntimeException thrown = new RuntimeException("test"); final SettableFuture<Integer> futureInteger = SettableFuture.create(); final SettableFuture<Boolean> futureBoolean = SettableFuture.create(); Runnable combiner = new Runnable() { @Override public void run() { assertTrue(futureInteger.isDone()); assertTrue(futureBoolean.isDone()); throw thrown; } }; ListenableFuture<?> futureResult = whenAllComplete(futureInteger, futureBoolean).run(combiner, directExecutor()); Integer integerPartial = 1; futureInteger.set(integerPartial); Boolean booleanPartial = true; futureBoolean.set(booleanPartial); try { getDone(futureResult); fail(); } catch (ExecutionException expected) { assertSame(thrown, expected.getCause()); } }
public void testWhenAllComplete_asyncResult() throws Exception { final SettableFuture<Integer> futureInteger = SettableFuture.create(); final SettableFuture<Boolean> futureBoolean = SettableFuture.create(); AsyncCallable<String> combiner = new AsyncCallable<String>() { @Override public ListenableFuture<String> call() throws Exception { return immediateFuture( createCombinedResult(getDone(futureInteger), getDone(futureBoolean))); } }; ListenableFuture<String> futureResult = whenAllComplete(futureInteger, futureBoolean).callAsync(combiner, directExecutor()); Integer integerPartial = 1; futureInteger.set(integerPartial); Boolean booleanPartial = true; futureBoolean.set(booleanPartial); assertEquals(createCombinedResult(integerPartial, booleanPartial), getDone(futureResult)); }
public void testWhenAllComplete_asyncError() throws Exception { final Exception thrown = new RuntimeException("test"); final SettableFuture<Integer> futureInteger = SettableFuture.create(); final SettableFuture<Boolean> futureBoolean = SettableFuture.create(); AsyncCallable<String> combiner = new AsyncCallable<String>() { @Override public ListenableFuture<String> call() throws Exception { assertTrue(futureInteger.isDone()); assertTrue(futureBoolean.isDone()); return immediateFailedFuture(thrown); } }; ListenableFuture<String> futureResult = whenAllComplete(futureInteger, futureBoolean).callAsync(combiner, directExecutor()); Integer integerPartial = 1; futureInteger.set(integerPartial); Boolean booleanPartial = true; futureBoolean.set(booleanPartial); try { getDone(futureResult); fail(); } catch (ExecutionException expected) { assertSame(thrown, expected.getCause()); } }
whenAllComplete(stringFuture, booleanFuture).callAsync(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).run(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).run(combiner, newSingleThreadExecutor());
whenAllComplete(stringFuture, booleanFuture).callAsync(combiner, newSingleThreadExecutor());
AtomicInteger errorCounter, Executor executor) { return Futures.whenAllComplete(futures) .call( () -> {
public void testWhenAllComplete_wildcard() throws Exception { ListenableFuture<?> futureA = immediateFuture("a"); ListenableFuture<?> futureB = immediateFuture("b"); ListenableFuture<?>[] futures = new ListenableFuture<?>[0]; Callable<String> combiner = new Callable<String>() { @Override public String call() throws Exception { return "hi"; } }; // We'd like for all the following to compile. ListenableFuture<String> unused; // Compiles: unused = whenAllComplete(futureA, futureB).call(combiner, directExecutor()); // Does not compile: // unused = whenAllComplete(futures).call(combiner); // Workaround for the above: unused = whenAllComplete(asList(futures)).call(combiner, directExecutor()); }
@GwtIncompatible // threads public void testWhenAllComplete_noLeakInterruption() throws Exception { final SettableFuture<String> stringFuture = SettableFuture.create(); AsyncCallable<String> combiner = new AsyncCallable<String>() { @Override public ListenableFuture<String> call() throws Exception { return stringFuture; } }; ListenableFuture<String> futureResult = whenAllComplete().callAsync(combiner, directExecutor()); assertThat(Thread.interrupted()).isFalse(); futureResult.cancel(true); assertThat(Thread.interrupted()).isFalse(); }
public void testWhenAllComplete_asyncResult() throws Exception { final SettableFuture<Integer> futureInteger = SettableFuture.create(); final SettableFuture<Boolean> futureBoolean = SettableFuture.create(); AsyncCallable<String> combiner = new AsyncCallable<String>() { @Override public ListenableFuture<String> call() throws Exception { return immediateFuture( createCombinedResult(getDone(futureInteger), getDone(futureBoolean))); } }; ListenableFuture<String> futureResult = whenAllComplete(futureInteger, futureBoolean).callAsync(combiner, directExecutor()); Integer integerPartial = 1; futureInteger.set(integerPartial); Boolean booleanPartial = true; futureBoolean.set(booleanPartial); assertEquals(createCombinedResult(integerPartial, booleanPartial), getDone(futureResult)); }
public void testWhenAllComplete_asyncError() throws Exception { final Exception thrown = new RuntimeException("test"); final SettableFuture<Integer> futureInteger = SettableFuture.create(); final SettableFuture<Boolean> futureBoolean = SettableFuture.create(); AsyncCallable<String> combiner = new AsyncCallable<String>() { @Override public ListenableFuture<String> call() throws Exception { assertTrue(futureInteger.isDone()); assertTrue(futureBoolean.isDone()); return immediateFailedFuture(thrown); } }; ListenableFuture<String> futureResult = whenAllComplete(futureInteger, futureBoolean).callAsync(combiner, directExecutor()); Integer integerPartial = 1; futureInteger.set(integerPartial); Boolean booleanPartial = true; futureBoolean.set(booleanPartial); try { getDone(futureResult); fail(); } catch (ExecutionException expected) { assertSame(thrown, expected.getCause()); } }
ListenableFuture<String> futureResult = whenAllComplete(stringFuture, booleanFuture) .callAsync(combiner, newSingleThreadExecutor());
ListenableFuture<String> futureResult = whenAllComplete(stringFuture, booleanFuture) .callAsync(combiner, newSingleThreadExecutor());