use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method essential_alreadyCompleted.
@Test
public void essential_alreadyCompleted() {
called = false;
FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
f.set(10);
assertTrue(f.isDone());
f.essential(event -> called = true);
assertTrue(called);
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method testAllOf.
@Test
public void testAllOf() throws InterruptedException {
for (int i = 0; i < TIMES; i++) {
complete = false;
FastFuture f1 = new FastFuture(FinalPipeline.empty(), a -> {
});
FastFuture f2 = new FastFuture(FinalPipeline.empty(), a -> {
});
CountDownLatch race = new CountDownLatch(1);
FastFuture allOf = FastFuture.allOf(() -> complete = true, f1, f2);
new Thread(() -> {
race.countDown();
f1.set("done");
f2.set("with");
}).start();
try {
race.await();
} catch (Exception e) {
e.printStackTrace();
}
race.await();
while (!complete) {
}
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method essential_notCompleted.
@Test
public void essential_notCompleted() {
called = false;
FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
f.essential(event -> called = true);
f.set(10);
assertTrue(f.isDone());
assertTrue(called);
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method testXOf.
@Test
public void testXOf() {
for (int i = 0; i < TIMES; i++) {
complete = false;
FastFuture f1 = new FastFuture(FinalPipeline.empty(), a -> {
});
FastFuture f2 = new FastFuture(FinalPipeline.empty(), a -> {
});
CountDownLatch race = new CountDownLatch(1);
FastFuture xOf = FastFuture.xOf(2, () -> complete = true, f1, f2);
new Thread(() -> {
race.countDown();
f1.set("done");
f2.set("with");
}).start();
try {
race.await();
} catch (Exception e) {
e.printStackTrace();
}
while (!complete) {
}
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onFail.
@Test
public void onFail() {
FastFuture f = future.onFail(t -> failed = t).thenApply(v -> {
throw new RuntimeException();
}).build();
f.set("boo!");
assertNotNull(failed);
}
Aggregations