Search in sources :

Example 11 with CompositeFuture

use of io.vertx.core.CompositeFuture in project vert.x by eclipse.

the class FutureTest method testJoinSucceeded.

private void testJoinSucceeded(BiFunction<Future<String>, Future<Integer>, CompositeFuture> join) {
    Future<String> f1 = Future.future();
    Future<Integer> f2 = Future.future();
    CompositeFuture composite = join.apply(f1, f2);
    Checker<CompositeFuture> checker = new Checker<>(composite);
    checker.assertNotCompleted();
    f1.complete("foo");
    checker.assertNotCompleted();
    f2.complete();
    checker.assertSucceeded(composite);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture)

Example 12 with CompositeFuture

use of io.vertx.core.CompositeFuture in project vert.x by eclipse.

the class FutureTest method testJoinFailed3.

private void testJoinFailed3(BiFunction<Future<String>, Future<Integer>, CompositeFuture> join) {
    Future<String> f1 = Future.future();
    Future<Integer> f2 = Future.future();
    CompositeFuture composite = join.apply(f1, f2);
    Checker<CompositeFuture> checker = new Checker<>(composite);
    checker.assertNotCompleted();
    Throwable cause1 = new Throwable();
    f1.fail(cause1);
    checker.assertNotCompleted();
    Throwable cause2 = new Throwable();
    f2.fail(cause2);
    assertSame(cause1, checker.assertFailed());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 13 with CompositeFuture

use of io.vertx.core.CompositeFuture in project vert.x by eclipse.

the class FutureTest method testAnyLargeList.

private void testAnyLargeList(int size) {
    List<Future> list = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        list.add(Future.failedFuture(new Exception()));
    }
    CompositeFuture composite = CompositeFuture.any(list);
    Checker<CompositeFuture> checker = new Checker<>(composite);
    checker.assertFailed();
    for (int i = 0; i < size; i++) {
        list.clear();
        for (int j = 0; j < size; j++) {
            list.add(i == j ? Future.succeededFuture() : Future.failedFuture(new RuntimeException()));
        }
        composite = CompositeFuture.any(list);
        checker = new Checker<>(composite);
        checker.assertSucceeded(composite);
        for (int j = 0; j < size; j++) {
            if (i == j) {
                assertTrue(composite.succeeded(j));
            } else {
                assertTrue(composite.failed(j));
            }
        }
    }
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) ArrayList(java.util.ArrayList) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture)

Example 14 with CompositeFuture

use of io.vertx.core.CompositeFuture in project vert.x by eclipse.

the class FutureTest method testAnyFailed.

private void testAnyFailed(BiFunction<Future<String>, Future<Integer>, CompositeFuture> any) {
    Future<String> f1 = Future.future();
    Future<Integer> f2 = Future.future();
    CompositeFuture composite = any.apply(f1, f2);
    Checker<CompositeFuture> checker = new Checker<>(composite);
    f1.fail("failure");
    checker.assertNotCompleted();
    Throwable cause = new Exception();
    f2.fail(cause);
    checker.assertFailed(cause);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 15 with CompositeFuture

use of io.vertx.core.CompositeFuture in project vert.x by eclipse.

the class FutureTest method testAnyWithEmptyList.

@Test
public void testAnyWithEmptyList() {
    CompositeFuture composite = CompositeFuture.any(Collections.emptyList());
    assertTrue(composite.isComplete());
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) Test(org.junit.Test)

Aggregations

CompositeFuture (io.vertx.core.CompositeFuture)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 NoStackTraceThrowable (io.vertx.core.impl.NoStackTraceThrowable)6 Test (org.junit.Test)6 Future (io.vertx.core.Future)2 ArrayList (java.util.ArrayList)2