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_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_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)); }