Map<CompletableFuture<Integer>, Integer> futures = createMappedNumericKeyFutures(count); completeKeyFutures(futures); CompletableFuture<Map<Integer, Integer>> allFuturesComplete = Futures.keysAllOfWithResults(futures); Assert.assertTrue("keysAllOfWithResults() did not create a completed future when all futures were previously complete.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); checkKeyResults(allFuturesComplete.join()); futures = createMappedNumericKeyFutures(count); allFuturesComplete = Futures.keysAllOfWithResults(futures); Assert.assertFalse("keysAllOfWithResults() created a completed future when none of the futures were previously complete.", allFuturesComplete.isDone()); completeKeyFutures(futures); Assert.assertTrue("The result of keysAllOfWithResults() complete when all its futures completed.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); checkKeyResults(allFuturesComplete.join()); futures = createMappedNumericKeyFutures(count); failRandomFuture(new ArrayList<>(futures.keySet())); allFuturesComplete = Futures.keysAllOfWithResults(futures); Assert.assertFalse("keysAllOfWithResults() created a completed future when not all of the futures were previously complete (but one failed).", allFuturesComplete.isDone()); completeKeyFutures(futures); Assert.assertTrue("The result of keysAllOfWithResults() did not complete exceptionally when at least one of the futures failed.", allFuturesComplete.isCompletedExceptionally()); futures = createMappedNumericKeyFutures(count); allFuturesComplete = Futures.keysAllOfWithResults(futures); failRandomFuture(new ArrayList<>(futures.keySet())); Assert.assertFalse("The result of keysAllOfWithResults() completed when not all the futures completed (except one that failed).",
Map<Integer, CompletableFuture<Integer>> futures = createMappedNumericFutures(count); 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.", allFuturesComplete.isDone() && !allFuturesComplete.isCompletedExceptionally()); checkResults(allFuturesComplete.join()); futures = createMappedNumericFutures(count); 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()); checkResults(allFuturesComplete.join()); futures = createMappedNumericFutures(count); failRandomFuture(new ArrayList<>(futures.values())); allFuturesComplete = Futures.allOfWithResults(futures); 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()); futures = createMappedNumericFutures(count); allFuturesComplete = Futures.allOfWithResults(futures); failRandomFuture(new ArrayList<>(futures.values())); Assert.assertFalse("The result of allOfWithResults() completed when not all the futures completed (except one that failed).",
List<CompletableFuture<Integer>> futures = createNumericFutures(count); 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.isDone() && !allFuturesComplete.isCompletedExceptionally()); checkResults(allFuturesComplete.join()); futures = createNumericFutures(count); 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()); checkResults(allFuturesComplete.join()); futures = createNumericFutures(count); failRandomFuture(futures); allFuturesComplete = Futures.allOfWithResults(futures); 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()); futures = createNumericFutures(count); allFuturesComplete = Futures.allOfWithResults(futures); failRandomFuture(futures); Assert.assertFalse("The result of allOfWithResults() completed when not all the futures completed (except one that failed).", allFuturesComplete.isDone());
List<CompletableFuture<Integer>> futures = createNumericFutures(count); 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()); futures = createNumericFutures(count); 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()); futures = createNumericFutures(count); failRandomFuture(futures); 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()); futures = createNumericFutures(count); allFuturesComplete = Futures.allOf(futures); 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());