use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class BlockingTest method testBreakoutAllCompletedAndTime.
@Test
public void testBreakoutAllCompletedAndTime() throws InterruptedException, ExecutionException {
count = new AtomicInteger(0);
List<Integer> result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).then(it -> {
sleep(it);
return it;
}).capture(e -> count.incrementAndGet()).block(status -> status.getAllCompleted() > 1 && status.getElapsedMillis() > 20);
assertThat(result.size(), is(2));
assertThat(count.get(), is(0));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class BlockingTest method testBlockStreamsSeparateExecutors.
@Test
public void testBlockStreamsSeparateExecutors() throws InterruptedException, ExecutionException {
Integer result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 200).block().parallelStream().filter(f -> f > 300).map(m -> m - 5).reduce(0, (acc, next) -> acc + next);
assertThat(result, is(990));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class BlockingTest method testBreakoutAllCompletedStrings.
@Test
public void testBreakoutAllCompletedStrings() throws InterruptedException, ExecutionException {
count = new AtomicInteger(0);
List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).then(it -> {
if (it == 100)
throw new RuntimeException("boo!");
else
sleep(it);
return it;
}).then(it -> "*" + it).capture(e -> count.incrementAndGet()).block(status -> status.getAllCompleted() > 0);
assertThat(strings.size(), is(0));
assertThat(count.get(), is(1));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class BlockingTest method testTypeInferencingThenPredicate.
@Test
public void testTypeInferencingThenPredicate() {
List<String> result = new SimpleReact().ofAsync(() -> "World", () -> "Hello").then(in -> "hello").block(state -> state.getCompleted() > 3);
assertThat(result.size(), is(2));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class ResultCollectionTest method testBreakoutExceptionTimes.
@Test
public void testBreakoutExceptionTimes() throws InterruptedException, ExecutionException {
count = 0;
List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<String>then(it -> {
throw new RuntimeException("boo!");
}).capture(e -> count++).block(status -> status.getCompleted() >= 1);
assertThat(strings.size(), is(0));
assertThat(count, is(3));
}
Aggregations