Search in sources :

Example 1 with CompositeFuture

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

the class FutureTest method testAllLargeList.

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

Example 2 with CompositeFuture

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

the class FutureTest method testCompositeComplete.

@Test
public void testCompositeComplete() {
    CompositeFuture composite = CompositeFuture.all(Future.future(), Future.future());
    Checker<CompositeFuture> checker = new Checker<>(composite);
    composite.complete(composite);
    checker.assertSucceeded(composite);
    composite = CompositeFuture.all(Future.future(), Future.future());
    checker = new Checker<>(composite);
    composite.complete();
    checker.assertSucceeded(composite);
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) Test(org.junit.Test)

Example 3 with CompositeFuture

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

the class FutureTest method testAllFailed.

private void testAllFailed(BiFunction<Future<String>, Future<Integer>, CompositeFuture> all) {
    Future<String> f1 = Future.future();
    Future<Integer> f2 = Future.future();
    CompositeFuture composite = all.apply(f1, f2);
    Checker<CompositeFuture> checker = new Checker<>(composite);
    f1.complete("s");
    Exception cause = new Exception();
    f2.fail(cause);
    checker.assertFailed(cause);
    assertEquals("s", composite.resultAt(0));
    assertEquals(null, composite.<Integer>resultAt(1));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture)

Example 4 with CompositeFuture

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

the class FutureTest method testJoinFailed1.

private void testJoinFailed1(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();
    Throwable cause = new Throwable();
    f2.fail(cause);
    assertSame(checker.assertFailed(), cause);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 5 with CompositeFuture

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

the class FutureTest method testAnySucceeded1.

private void testAnySucceeded1(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);
    checker.assertNotCompleted();
    assertEquals(null, composite.<String>resultAt(0));
    assertEquals(null, composite.<Integer>resultAt(1));
    f1.complete("something");
    checker.assertSucceeded(composite);
    f2.complete(3);
    checker.assertSucceeded(composite);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture)

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