use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onCompleteWithNoPipeline_notCompleted_race.
@Test
public void onCompleteWithNoPipeline_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.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 onFailRecovered3.
@Test
public void onFailRecovered3() {
FastFuture f = future.onFail(t -> failed = t).exceptionally(e -> {
if (e instanceof IOException)
return "hello world";
throw (RuntimeException) e;
}).exceptionally(e -> {
if (e instanceof FileNotFoundException)
return "hello world2";
throw (RuntimeException) e;
}).exceptionally(e -> {
if (e instanceof RuntimeException)
return "hello world3";
throw (RuntimeException) e;
}).thenApply(v -> {
throw new RuntimeException();
}).build();
f.set("boo!");
assertThat(f.join(), equalTo("hello world3"));
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onCompleteReversed_notCompleted_race.
@Test
public void onCompleteReversed_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.set(10);
});
t1.start();
race.countDown();
f.onComplete(event -> called = true);
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 onFailRecovered2.
@Test
public void onFailRecovered2() {
FastFuture f = future.onFail(t -> failed = t).exceptionally(e -> {
if (e instanceof IOException)
return "hello world";
throw (RuntimeException) e;
}).exceptionally(e -> {
if (e instanceof RuntimeException)
return "hello world2";
throw (RuntimeException) e;
}).thenApply(v -> {
throw new RuntimeException();
}).build();
f.set("boo!");
assertThat(f.join(), equalTo("hello world2"));
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method firstRecoverOrder.
@Test
public void firstRecoverOrder() {
FastFuture f = future.thenApply(v -> {
throw new RuntimeException();
}).exceptionally(e -> "hello world").build();
f.set("boo!");
assertThat(f.join(), equalTo("hello world"));
}
Aggregations