completeFutures(futures); CompletableFuture<Map<Integer, Integer>> allFuturesComplete = Futures.allOfWithResults(futures); Assert.assertTrue("allOfWithResults() did not create a completed future when all futures were previously complete.", Assert.assertFalse("allOfWithResults() created a completed future when none of the futures were previously complete.", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOfWithResults() complete when all its futures completed.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); Assert.assertFalse("allOfWithResults() created a completed future when not all of the futures were previously complete (but one failed).", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOfWithResults() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally()); Assert.assertFalse("The result of allOfWithResults() completed when not all the futures completed (except one that failed).", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOfWithResults() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally());
completeFutures(futures); CompletableFuture<Void> allFuturesComplete = Futures.allOf(futures); Assert.assertTrue("allOf() did not create a completed future when all futures were previously complete.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); allFuturesComplete = Futures.allOf(futures); Assert.assertFalse("allOf() created a completed future when none of the futures were previously complete.", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOf() complete when all its futures completed.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); allFuturesComplete = Futures.allOf(futures); Assert.assertFalse("allOf() created a completed future when not all of the futures were previously complete (but one failed).", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOf() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally()); failRandomFuture(futures); Assert.assertFalse("The result of allOf() completed when not all the futures completed (except one that failed).", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOf() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally());
completeFutures(futures); CompletableFuture<List<Integer>> allFuturesComplete = Futures.allOfWithResults(futures); Assert.assertTrue("allOfWithResults() did not create a completed future when all futures were previously complete.", allFuturesComplete = Futures.allOfWithResults(futures); Assert.assertFalse("allOfWithResults() created a completed future when none of the futures were previously complete.", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOfWithResults() complete when all its futures completed.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); Assert.assertFalse("allOfWithResults() created a completed future when not all of the futures were previously complete (but one failed).", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOfWithResults() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally()); Assert.assertFalse("The result of allOfWithResults() completed when not all the futures completed (except one that failed).", allFuturesComplete.isDone()); completeFutures(futures); Assert.assertTrue("The result of allOfWithResults() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally());