use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onComplete_alreadyCompleted.
@Test
public void onComplete_alreadyCompleted() {
called = false;
FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
f.set(10);
assertTrue(f.isDone());
f.onComplete(event -> called = true);
assertTrue(called);
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method essentialReversed_notCompleted_race.
@Test
public void essentialReversed_notCompleted_race() throws InterruptedException {
for (int i = 0; i < TIMES; i++) {
System.out.println(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.essential(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 BatchingCollectorTest method testAcceptMock.
@Test
public void testAcceptMock() {
FastFuture cf = Mockito.mock(FastFuture.class);
BDDMockito.given(cf.isDone()).willReturn(true);
for (int i = 0; i < 1000; i++) {
collector.accept(cf);
}
Mockito.verify(cf, Mockito.atLeastOnce()).isDone();
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class BatchingCollectorTest method testAcceptMock50.
@Test
public void testAcceptMock50() {
collector = new BatchingCollector(new MaxActive(500, 450), LazyReact.sequentialBuilder().of(1)).withResults(new ArrayList<>());
FastFuture cf = Mockito.mock(FastFuture.class);
BDDMockito.given(cf.isDone()).willReturn(true);
for (int i = 0; i < 1000; i++) {
collector.accept(cf);
}
Mockito.verify(cf, Mockito.times(501)).isDone();
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class LazyStream method runThread.
default void runThread(final Runnable r) {
final Function<FastFuture, U> safeJoin = (final FastFuture cf) -> (U) BlockingStreamHelper.getSafe(cf, getErrorHandler());
new Thread(() -> new Runner(r).run(getLastActive(), new EmptyCollector(getMaxActive(), safeJoin))).start();
}
Aggregations