private static void makeCompleteListFutureTest(int errorIndex) throws InterruptedException, TimeoutException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, errorIndex); ListenableFuture<List<ListenableFuture<?>>> f = FutureUtils.makeCompleteListFuture(futures); verifyCompleteFuture(f, futures); verifyAllIncluded(futures, f.get(), null); }
@Test public void makeSuccessListFutureWithCancelErrorTest() throws ExecutionException, InterruptedException, TimeoutException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); SettableListenableFuture<?> cancelFuture = new SettableListenableFuture<>(); cancelFuture.cancel(false); futures.add(cancelFuture); ListenableFuture<List<ListenableFuture<?>>> f = FutureUtils.makeSuccessListFuture(futures); verifyCompleteFuture(f, futures); verifyAllIncluded(futures, f.get(), cancelFuture); }
@Test public void makeSuccessListFutureWithErrorTest() throws ExecutionException, InterruptedException, TimeoutException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); SettableListenableFuture<?> failureFuture = new SettableListenableFuture<>(); failureFuture.setFailure(null); futures.add(failureFuture); ListenableFuture<List<ListenableFuture<?>>> f = FutureUtils.makeSuccessListFuture(futures); verifyCompleteFuture(f, futures); verifyAllIncluded(futures, f.get(), failureFuture); }
@Test public void makeCompleteListFutureAlreadyDoneFuturesTest() throws InterruptedException, ExecutionException { List<ListenableFuture<?>> futures = new ArrayList<>(TEST_QTY); for (int i = 0; i < TEST_QTY; i++) { SettableListenableFuture<?> future = new SettableListenableFuture<>(); if (i == TEST_QTY / 2) { future.setFailure(null); } else { future.setResult(null); } futures.add(future); } ListenableFuture<List<ListenableFuture<?>>> f = FutureUtils.makeCompleteListFuture(futures); assertTrue(f.isDone()); verifyAllIncluded(futures, f.get(), null); }
@Test public void makeSuccessListFutureAlreadyDoneFuturesTest() throws InterruptedException, ExecutionException { List<ListenableFuture<?>> futures = new ArrayList<>(TEST_QTY); ListenableFuture<?> failureFuture = null; for (int i = 0; i < TEST_QTY; i++) { SettableListenableFuture<?> future = new SettableListenableFuture<>(); if (i == TEST_QTY / 2) { failureFuture = future; future.setFailure(null); } else { future.setResult(null); } futures.add(future); } ListenableFuture<List<ListenableFuture<?>>> f = FutureUtils.makeSuccessListFuture(futures); assertTrue(f.isDone()); verifyAllIncluded(futures, f.get(), failureFuture); }