use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class ResultCollectionTest method testBreakoutAllCompleted.
@Test
public void testBreakoutAllCompleted() throws InterruptedException, ExecutionException {
count = 0;
List<Integer> results = 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;
}).capture(e -> count++).block(status -> status.getAllCompleted() > 0);
assertThat(results.size(), is(0));
assertThat(count, is(1));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class ResultCollectionTest method testBreakoutException.
@Test
public void testBreakoutException() throws InterruptedException, ExecutionException {
Throwable[] error = { null };
List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<String>then(it -> {
throw new RuntimeException("boo!");
}).capture(e -> error[0] = e).block(status -> status.getCompleted() >= 1);
assertThat(strings.size(), is(0));
assertThat(error[0], instanceOf(RuntimeException.class));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AlgorithmCompareTest method testFastest.
@Test
public void testFastest() throws InterruptedException, ExecutionException {
ArrayList<Integer> arrayList = new ArrayList<>();
LinkedList<Integer> linkedList = new LinkedList<>();
for (int i = 0; i < 1001; i++) {
arrayList.add(i);
linkedList.add(i);
}
SimpleTimer timer = new SimpleTimer();
Result result = new SimpleReact().<Result>ofAsync(() -> Result.builder().name("approach1").result(retrieval(arrayList)).build(), () -> Result.builder().name("approach2").result(retrieval(linkedList)).build()).then(it -> it.withTime(timer.getElapsedNanoseconds())).filter(it -> it.getResult() == 1000).block().firstValue(null);
assertThat(result.getName(), is("approach1"));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class BlockingTest method testFirstAllOf.
@Test
public void testFirstAllOf() 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(), it -> {
assertThat(it, is(Set.class));
return it;
}).block().firstValue(null);
assertThat(result.size(), is(4));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class FilterTest method testFilterExceptions.
@Test
public void testFilterExceptions() throws InterruptedException, ExecutionException {
List<String> result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).filter(it -> 1 != it).<String>then(it -> "*" + it).capture(e -> fail("No exception should be captured")).block();
assertThat(result.size(), is(2));
assertThat(result, not(hasItem("*1")));
}
Aggregations