Search in sources :

Example 6 with CompositeFuture

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

the class FutureTest method testCompositeFutureToList.

@Test
public void testCompositeFutureToList() {
    Future<String> f1 = Future.future();
    Future<Integer> f2 = Future.future();
    CompositeFuture composite = CompositeFuture.all(f1, f2);
    assertEquals(Arrays.asList(null, null), composite.list());
    f1.complete("foo");
    assertEquals(Arrays.asList("foo", null), composite.list());
    f2.complete(4);
    assertEquals(Arrays.asList("foo", 4), composite.list());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeFuture(io.vertx.core.CompositeFuture) Test(org.junit.Test)

Example 7 with CompositeFuture

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

the class FutureTest method testJoinFailed2.

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

Example 8 with CompositeFuture

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

the class FutureTest method testAllSucceeded.

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

Example 9 with CompositeFuture

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

the class FutureTest method testCompositeFail.

@Test
public void testCompositeFail() {
    Throwable cause = new Throwable();
    Future<Object> f1 = Future.future();
    Future<Object> f2 = Future.future();
    CompositeFuture composite = CompositeFuture.all(f1, f2);
    Checker<CompositeFuture> checker = new Checker<>(composite);
    composite.fail(cause);
    checker.assertFailed(cause);
    f1.complete();
    f2.complete();
    checker.assertFailed(cause);
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) Test(org.junit.Test)

Example 10 with CompositeFuture

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

the class FutureTest method testAnySucceeded2.

private void testAnySucceeded2(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();
    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