use of com.oath.cyclops.types.futurestream.BaseSimpleReactStream 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 com.oath.cyclops.types.futurestream.BaseSimpleReactStream in project cyclops by aol.
the class SimpleReactTest method asyncTest.
@Test
public void asyncTest() {
BaseSimpleReactStream stream = BaseSimpleReactStream.of(1, 2, 3, 4).async();
assertThat(stream.isAsync(), is(true));
}
use of com.oath.cyclops.types.futurestream.BaseSimpleReactStream in project cyclops by aol.
the class SimpleReactTest method syncTest.
@Test
public void syncTest() {
BaseSimpleReactStream stream = BaseSimpleReactStream.of(1, 2, 3, 4).sync();
assertThat(stream.isAsync(), is(false));
}
use of com.oath.cyclops.types.futurestream.BaseSimpleReactStream in project cyclops by aol.
the class TopicTest method multipleSubscribersGetSameMessagesSimpleReact.
@Test
public void multipleSubscribersGetSameMessagesSimpleReact() throws InterruptedException, ExecutionException {
Topic<String> topic = new Topic<>(new Queue<>());
Stream<String> input = Stream.of("hello", "world");
// read from the topic concurrently in 2 threads
BaseSimpleReactStream<Collection<String>> stage = new SimpleReact(new ForkJoinPool(2)).ofAsync(() -> parallel().fromStream(topic.stream()).then(it -> it + "*").block(), () -> parallel().fromStream(topic.stream()).then(it -> it + "!").peek(// make sure takes slightly longer to complete
it -> sleep(10)).block(Collectors.toSet()));
// make sure streams are set up
sleep(50);
topic.fromStream(input);
// wait until Topic has been read from
sleep(400);
topic.close();
List<Collection<String>> result = stage.block();
assertThat(result.get(0), instanceOf(List.class));
assertThat(result.get(0), hasItem("hello*"));
assertThat(result.get(0), hasItem("world*"));
assertThat(result.get(1), instanceOf(HashSet.class));
assertThat(result.get(1), hasItem("hello!"));
assertThat(result.get(1), hasItem("world!"));
}
use of com.oath.cyclops.types.futurestream.BaseSimpleReactStream in project cyclops by aol.
the class CompletableFutureTest method asyncEventRecieverTest.
@Test
public void asyncEventRecieverTest() throws InterruptedException, ExecutionException {
Queue<CompletableFuture<Integer>> queue = buildQueueOfAsyncEvents();
BaseSimpleReactStream<String> convertedToStrings = new SimpleReact().fromStream(queue.stream()).<String>then(it -> it + "*");
convertedToStrings.streamCompletableFutures().forEach(f -> assertFalse(f.isDone()));
new SimpleReact(new ForkJoinPool(3)).ofAsync(() -> 100, () -> 200, () -> 400).then(it -> sleep(it)).then(it -> queue.poll().complete(it));
List<String> result = convertedToStrings.block();
assertThat(result.size(), is(3));
assertThat(result, hasItem("400*"));
}
Aggregations