use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testLargeChain.
@Test
public void testLargeChain() {
BaseSimpleReactStream builder = new SimpleReact().ofAsync(() -> "Hello", () -> "World");
for (int i = 0; i < 1000; i++) {
builder = builder.then(input -> input + " " + counter++);
}
List<String> results = builder.block();
assertThat(results.get(0).length(), greaterThan(100));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testEagetParameters.
@Test
public void testEagetParameters() {
ForkJoinPool fjp = new ForkJoinPool();
assertThat(new SimpleReact(fjp).getExecutor(), is(fjp));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testMultithreading.
@Test
public void testMultithreading() throws InterruptedException, ExecutionException {
Set<Long> threads = new SimpleReact(new ForkJoinPool(10)).<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 3, () -> 3, () -> 3, () -> 3).peek(it -> sleep(50l)).then(it -> Thread.currentThread().getId()).block(Collectors.toSet());
assertThat(threads.size(), is(greaterThan(1)));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testGenericExtract.
@Test
public void testGenericExtract() throws InterruptedException, ExecutionException {
Set<Integer> result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 5).then(it -> it * 100).<Set<Integer>, Set<Integer>>allOf(Collectors.toSet(), (Set<Integer> it) -> {
assertThat(it, instanceOf(Set.class));
return it;
}).capture(e -> e.printStackTrace()).block(status -> false).takeRight(1).get(0);
assertThat(result.size(), is(4));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testCustomExecutor.
@Test
public void testCustomExecutor() {
ExecutorService executor = Mockito.mock(ExecutorService.class);
Mockito.doAnswer((invocation) -> {
((Runnable) invocation.getArguments()[0]).run();
return null;
}).when(executor).execute(Matchers.any(Runnable.class));
new SimpleReact(executor).ofAsync(() -> "Hello", () -> "World").block();
Mockito.verify(executor, Mockito.times(2)).execute(Matchers.any(Runnable.class));
}
Aggregations