@Test
public void testAnyOf() throws Throwable {

    TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION);
    int count = 10;
    List<DeferredResult<Integer>> deferredResults = IntStream.range(0, count)
            .mapToObj(ignore -> new DeferredResult<Integer>())
            .collect(Collectors.toList());
    DeferredResult<Integer> deferredResult = DeferredResult.anyOf(deferredResults);
    deferredResult.whenComplete(ctx.getCompletionDeferred());
    int fastest = 7;
    CountDownLatch latch = new CountDownLatch(1);
    IntStream.range(0, count).forEach(i -> {
        if (i == fastest) {
            runAfter(1, () -> {
                deferredResults.get(i).complete(i);
                latch.countDown();
            });
        } else {
            runAfter(1, () -> {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                }
                deferredResults.get(i).complete(i);
            });
        }
    });
    ctx.await();
    Assert.assertEquals(fastest, deferredResult.getNow(exceptionSupplier()).intValue());
}