use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method testThenApplyAsync.
@Test
public void testThenApplyAsync() {
try {
future = future.<String, String>thenApplyAsync(String::toUpperCase, ForkJoinPool.commonPool()).peek(System.out::println).<String, Integer>thenApply(s -> s.length()).thenApply(l -> {
sizes.add((Integer) l);
return l;
}).peek(System.out::println).<Integer, Integer>thenApplyAsync(l -> l + 2, ForkJoinPool.commonPool()).peek(System.out::println).<Integer, Integer>thenApply(l -> {
sizes2.add(l);
return l;
}).<Integer, Integer>thenApplyAsync(l -> l + 2, ForkJoinPool.commonPool()).peek(System.out::println).<Integer, Integer>thenApply(l -> {
sizes3.add(l);
return l;
});
StringBuilder suffix = new StringBuilder();
for (int i = 0; i < 100; i++) {
FastFuture f2 = future.build();
f2.set("hello world" + suffix.toString());
f2.join();
FastFuture f3 = future.build();
f3.set("hello world2" + suffix.toString());
f3.join();
suffix.append("" + i);
}
for (int i = 0; i < 11; i++) {
assertFalse(sizes.contains(i));
}
for (int i = 11; i < 201; i++) {
assertTrue(sizes.contains(i));
}
for (int i = 201; i < 211; i++) {
assertFalse(sizes.contains(i));
}
System.out.println(sizes);
System.out.println(sizes2);
System.out.println(sizes3);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method testAnyOf.
@Test
public void testAnyOf() {
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 anyOf = FastFuture.anyOf(f1, f2);
new Thread(() -> {
race.countDown();
f1.set("done");
f2.set("with");
}).start();
try {
race.await();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
anyOf.join();
}
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class FastFutureTest method onComplete_notCompleted.
@Test
public void onComplete_notCompleted() {
called = false;
FastFuture f = future.<Integer, Integer>thenApply(i -> i + 2).build();
f.onComplete(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 BatchingCollectorTest method testBuilder.
@Test
public void testBuilder() {
collector = BatchingCollector.builder().blocking(LazyReact.sequentialBuilder().of(1)).maxActive(new MaxActive(2, 1)).results(new ArrayList<>()).build();
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(999)).isDone();
}
use of com.oath.cyclops.internal.react.async.future.FastFuture in project cyclops by aol.
the class BatchingCollectorTest method testWithMaxActive.
@Test
public void testWithMaxActive() {
collector = collector.withMaxActive(new MaxActive(10000, 5));
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(0)).isDone();
}
Aggregations