use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AllOfTest method testAllOfParallelStreamsSameForkJoinPool.
@Test
public void testAllOfParallelStreamsSameForkJoinPool() throws InterruptedException, ExecutionException {
Set<String> threadGroup = Collections.synchronizedSet(new TreeSet());
Integer result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 5).<Integer>then(it -> {
threadGroup.add(Thread.currentThread().getThreadGroup().getName());
return it * 200;
}).then((Integer it) -> {
if (it == 1000)
throw new RuntimeException("boo!");
return it;
}).onFail(e -> 100).allOf(it -> {
return it.parallelStream().filter(f -> f > 300).map(m -> {
threadGroup.add(Thread.currentThread().getThreadGroup().getName());
return m - 5;
}).reduce(0, (acc, next) -> acc + next);
}).block(Collectors.reducing(0, (acc, next) -> next));
assertThat(threadGroup.size(), is(1));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AllOfTest method testAllOfCompletableOnFail.
@Test
public void testAllOfCompletableOnFail() {
List<String> urls = Arrays.asList("hello", "world", "2");
List<String> result = new SimpleReact().fromStream(urls.stream().<CompletableFuture<String>>map(it -> handle(it))).onFail(it -> "hello").capture(e -> e.printStackTrace()).peek(it -> System.out.println(it)).allOf((List<String> data) -> {
System.out.println(data);
return data;
}).block().firstValue(null);
assertThat(result.size(), is(3));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AllOfTest method testAllOf.
@Test
public void testAllOf() throws InterruptedException, ExecutionException {
boolean[] blocked = { false };
new SimpleReact().<Integer>ofAsync(() -> 1).then(it -> {
try {
Thread.sleep(10);
} catch (Exception e) {
}
blocked[0] = true;
return 10;
}).allOf(it -> it.size());
assertThat(blocked[0], is(false));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AllOfTest method testAllOfParallelStreamsSkip.
@Test
public void testAllOfParallelStreamsSkip() throws InterruptedException, ExecutionException {
List<Integer> result = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3, () -> 5).<Integer>then(it -> {
return it * 200;
}).then((Integer it) -> {
if (it == 1000)
throw new RuntimeException("boo!");
return it;
}).onFail(e -> 100).allOf(it -> {
return it.parallelStream().skip(1).limit(3).collect(Collectors.toList());
}).block().firstValue(null);
assertThat(result.size(), is(3));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class BlockingTest method testBreakoutAllCompleted.
@Test
public void testBreakoutAllCompleted() throws InterruptedException, ExecutionException {
count = new AtomicInteger(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.incrementAndGet()).block(status -> status.getAllCompleted() > 0);
assertThat(results.size(), is(0));
assertThat(count.get(), is(1));
}
Aggregations