use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onFailRecovered.
@Test
public void onFailRecovered() {
FastFuture f = future.onFail(t -> failed = t).exceptionally(e -> "hello world").thenApply(v -> {
throw new RuntimeException();
}).build();
f.set("boo!");
assertThat(f.join(), equalTo("hello world"));
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onComplete_notCompleted_race.
@Test
public void onComplete_notCompleted_race() throws InterruptedException {
for (int i = 0; i < TIMES; i++) {
CountDownLatch race = new CountDownLatch(1);
CountDownLatch init = new CountDownLatch(1);
called = false;
FastFuture f = future.<Integer, Integer>thenApply(x -> x + 2).build();
Thread t1 = new Thread(() -> {
init.countDown();
try {
race.await();
} catch (Exception e) {
e.printStackTrace();
}
f.onComplete(event -> called = true);
});
t1.start();
race.countDown();
f.set(10);
t1.join();
assertTrue(f.isDone());
assertTrue(called);
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method essential_notCompleted_race.
@Test
public void essential_notCompleted_race() throws InterruptedException {
for (int i = 0; i < TIMES; i++) {
CountDownLatch race = new CountDownLatch(1);
CountDownLatch init = new CountDownLatch(1);
called = false;
FastFuture f = future.<Integer, Integer>thenApply(x -> x + 2).build();
Thread t1 = new Thread(() -> {
init.countDown();
try {
race.await();
} catch (Exception e) {
e.printStackTrace();
}
f.essential(event -> called = true);
});
t1.start();
init.await();
race.countDown();
f.set(10);
t1.join();
assertTrue(f.isDone());
assertTrue(called);
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onFailNull.
@Test
public void onFailNull() {
FastFuture f = future.thenApply(v -> {
throw new RuntimeException();
}).build();
f.set("boo!");
assertNull(failed);
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method essential_withNoPipeline_notCompleted_race.
@Test
public void essential_withNoPipeline_notCompleted_race() throws InterruptedException {
for (int i = 0; i < TIMES; i++) {
CountDownLatch race = new CountDownLatch(1);
CountDownLatch init = new CountDownLatch(1);
called = false;
FastFuture f = future.build();
Thread t1 = new Thread(() -> {
init.countDown();
try {
race.await();
} catch (Exception e) {
e.printStackTrace();
}
f.essential(event -> called = true);
});
t1.start();
race.countDown();
f.set(10);
t1.join();
assertTrue(f.isDone());
assertTrue(called);
}
}
Aggregations