use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testReactExceptionRecovery.
@Test
public void testReactExceptionRecovery() {
List<String> result = new SimpleReact().ofAsync(() -> {
throw new RuntimeException();
}, () -> "Hello").onFail(e -> {
System.out.println(e);
return "World";
}).block();
assertThat(result.size(), is(2));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class StreamTest method testStreamOf.
@Test
public void testStreamOf() throws InterruptedException, ExecutionException {
Stream<CompletableFuture<String>> stream = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> "*" + it).streamCompletableFutures();
List<String> strings = new SimpleReact().<String>fromStream(stream).then(it -> it + "*").block();
assertThat(strings.size(), is(3));
assertThat(strings, hasItem("*1*"));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class StreamTest method testStreamFrom.
@Test
public void testStreamFrom() throws InterruptedException, ExecutionException {
List<String> strings = new SimpleReact().<String>fromStream(new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).with(it -> "*" + it).stream()).then(it -> it + "*").block();
assertThat(strings.size(), is(3));
assertThat(strings, hasItem("*1*"));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class ReactPoolTest method testUnboundedRoundRobin.
@Test
public void testUnboundedRoundRobin() {
SimpleReact react1 = Mockito.mock(SimpleReact.class);
SimpleReact react2 = Mockito.mock(SimpleReact.class);
SimpleReact react3 = Mockito.mock(SimpleReact.class);
ReactPool<SimpleReact> pool = ReactPool.unboundedPool(asList(react1, react2));
pool.populate(react3);
List<Supplier<String>> suppliers = Arrays.asList(() -> "hello", () -> "world");
pool.react((er) -> er.fromIterableAsync(suppliers));
pool.react((er) -> er.fromIterableAsync(suppliers));
pool.react((er) -> er.fromIterableAsync(suppliers));
Mockito.verify(react1, Mockito.times(1)).fromIterableAsync(suppliers);
Mockito.verify(react2, Mockito.times(1)).fromIterableAsync(suppliers);
Mockito.verify(react3, Mockito.times(1)).fromIterableAsync(suppliers);
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AnyOfTest method testAnyOfCompletableOnFail.
@Test
public void testAnyOfCompletableOnFail() {
List<String> urls = Arrays.asList("hello", "world", "2");
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)).anyOf(data -> {
System.out.println(data);
return data;
}).block().firstValue(null);
assertThat(urls, hasItem(result));
}
Aggregations