@Test public void blockTillAllCompleteWithTimeoutErrorTest() throws InterruptedException, TimeoutException { int errorIndex = TEST_QTY / 2; List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, errorIndex); FutureUtils.blockTillAllComplete(futures, 1000 * 10); Iterator<ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { assertTrue(it.next().isDone()); } }
@Test public void blockTillAllCompleteTest() throws InterruptedException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); FutureUtils.blockTillAllComplete(futures); Iterator<ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { assertTrue(it.next().isDone()); } }
@Test public void blockTillAllCompleteWithTimeoutTest() throws InterruptedException, TimeoutException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); FutureUtils.blockTillAllComplete(futures, 1000 * 10); Iterator<ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { assertTrue(it.next().isDone()); } }
@Test public void blockTillAllCompleteOrFirstErrorTest() throws InterruptedException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); FutureUtils.blockTillAllCompleteOrFirstError(futures); Iterator<ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { assertTrue(it.next().isDone()); } }
@Test public void blockTillAllCompleteOrFirstErrorWithTimeoutTest() throws InterruptedException, ExecutionException, TimeoutException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); FutureUtils.blockTillAllCompleteOrFirstError(futures, 1000 * 10); Iterator<ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { assertTrue(it.next().isDone()); } }
@Test public void blockTillAllCompleteErrorTest() throws InterruptedException { int errorIndex = TEST_QTY / 2; List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, errorIndex); FutureUtils.blockTillAllComplete(futures); Iterator<ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { assertTrue(it.next().isDone()); } }
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); }
private static void makeCompleteFutureTest(int errorIndex) throws InterruptedException, TimeoutException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, errorIndex); ListenableFuture<?> f = FutureUtils.makeCompleteFuture(futures); verifyCompleteFuture(f, futures); assertNull(f.get()); }
@Test public void makeResultListFutureIgnoreFailureTest() throws InterruptedException, ExecutionException { List<ListenableFuture<? extends String>> futures = makeFutures(TEST_QTY, TEST_QTY / 2); ListenableFuture<List<String>> resultFuture = FutureUtils.makeResultListFuture(futures, true); assertTrue(resultFuture.isDone()); assertEquals(TEST_QTY - 1, resultFuture.get().size()); }
@Test public void makeCompleteFutureWithNullResultTest() throws InterruptedException, TimeoutException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); ListenableFuture<?> f = FutureUtils.makeCompleteFuture(futures, null); verifyCompleteFuture(f, futures); assertNull(f.get()); }
@Test public void makeResultListFutureAlreadyDoneFuturesTest() throws InterruptedException, ExecutionException { List<ListenableFuture<? extends String>> futures = makeFutures(TEST_QTY, -1); ListenableFuture<List<String>> resultFuture = FutureUtils.makeResultListFuture(futures, false); assertTrue(resultFuture.isDone()); assertEquals(TEST_QTY, resultFuture.get().size()); }
@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 makeFailurePropagatingCompleteFuturePropagateFailureTest() { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, TEST_QTY / 2); ListenableFuture<?> f = FutureUtils.makeFailurePropagatingCompleteFuture(futures); try { f.get(); fail("Exception should have thrown"); } catch (ExecutionException e) { // expected } catch (InterruptedException e) { fail("Interrupted?"); } }
@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 makeFailurePropagatingCompleteFutureTest() throws InterruptedException, TimeoutException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); ListenableFuture<?> f = FutureUtils.makeFailurePropagatingCompleteFuture(futures); verifyCompleteFuture(f, futures); assertNull(f.get()); }
@Test public void makeFailurePropagatingCompleteFutureWithNullResultTest() throws InterruptedException, TimeoutException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); ListenableFuture<?> f = FutureUtils.makeFailurePropagatingCompleteFuture(futures, null); verifyCompleteFuture(f, futures); assertNull(f.get()); }
@Test public void makeFailureListFutureWithErrorTest() throws InterruptedException, TimeoutException, ExecutionException { List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); SettableListenableFuture<?> failureFuture = new SettableListenableFuture<>(); failureFuture.setFailure(null); futures.add(failureFuture); ListenableFuture<List<ListenableFuture<?>>> f = FutureUtils.makeFailureListFuture(futures); verifyCompleteFuture(f, futures); verifyNoneIncluded(futures, f.get(), failureFuture); }
@Test public void makeCompleteFutureWithResultAlreadyDoneTest() throws InterruptedException, TimeoutException, ExecutionException { String result = StringUtils.makeRandomString(5); List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); ListenableFuture<String> f = FutureUtils.makeCompleteFuture(futures, result); verifyCompleteFuture(f, futures); assertEquals(result, f.get()); }
@Test public void makeFailurePropagatingCompleteFutureWithResultAlreadyDoneTest() throws InterruptedException, TimeoutException, ExecutionException { String result = StringUtils.makeRandomString(5); List<ListenableFuture<?>> futures = makeFutures(TEST_QTY, -1); ListenableFuture<String> f = FutureUtils.makeFailurePropagatingCompleteFuture(futures, result); verifyCompleteFuture(f, futures); assertEquals(result, f.get()); }
@Test (expected = ExecutionException.class) public void makeResultListFutureWithFailureTest() throws InterruptedException, ExecutionException { List<ListenableFuture<? extends String>> futures = makeFutures(TEST_QTY, TEST_QTY / 2); ListenableFuture<List<String>> resultFuture = FutureUtils.makeResultListFuture(futures, false); assertTrue(resultFuture.isDone()); resultFuture.get(); fail("Exception should have thrown"); }