use of cyclops.futurestream.SimpleReact 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*"));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SignalTest method signalDiscrete1.
@Test
public void signalDiscrete1() {
for (int i = 0; i < 100; i++) {
resetFound();
try {
Signal<Integer> q = Signal.queueBackedSignal();
new SimpleReact().ofAsync(() -> q.set(1), () -> q.set(1), () -> {
sleep(200);
return q.set(1);
}, () -> {
sleep(40);
q.close();
return 1;
});
parallel().fromStreamOfFutures(q.getDiscrete().streamCompletableFutures()).then(it -> "*" + it).peek(it -> incrementFound()).peek(it -> System.out.println(it)).block();
} finally {
assertThat(found, is(1));
}
}
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SignalTest method signalContinuous3.
@Test
public void signalContinuous3() {
for (int i = 0; i < 10; i++) {
System.out.println(i);
resetFound();
try {
Signal<Integer> q = Signal.queueBackedSignal();
new SimpleReact().ofAsync(() -> q.set(1), () -> q.set(1), () -> {
sleep(1);
return q.set(1);
}, () -> {
sleep(150);
q.close();
return 1;
});
parallel().fromStream(q.getContinuous().streamCompletableFutures()).then(it -> "*" + it).peek(it -> incrementFound()).peek(it -> System.out.println(it)).block();
} finally {
assertThat(getFound(), is(3));
}
}
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class TopicTest method simpleMergingAndSplittingSimpleReact.
@Test
public void simpleMergingAndSplittingSimpleReact() {
Topic<Integer> topic = new Topic<>();
BaseSimpleReactStream<Collection<String>> stage = new SimpleReact(new ForkJoinPool(2)).ofAsync(() -> parallel().fromStream(topic.stream()).then(it -> it + "*").block(Collectors.toList()), () -> parallel().fromStream(topic.stream()).then(it -> it + "!").block(Collectors.toSet()));
// make sure streams are set up
sleep(50);
topic.offer(count);
topic.offer(count1);
// wait until Topic has been read from
sleep(40);
System.out.println("Closing!");
topic.close();
System.out.println("Closed! Blocking..");
List<Collection<String>> result = stage.block();
System.out.println("Completed " + result.size());
assertThat(extract1(result), hasItem("0*"));
assertThat(extract1(result), hasItem("100000*"));
assertThat(extract2(result), hasItem("0!"));
assertThat(extract2(result), hasItem("100000!"));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class AnyOfTest method testAnyOf.
@Test
public void testAnyOf() throws InterruptedException, ExecutionException {
boolean[] blocked = { false };
new SimpleReact().<Integer>ofAsync(() -> 1).then(it -> {
try {
Thread.sleep(50);
} catch (Exception e) {
}
blocked[0] = true;
return 10;
}).anyOf(it -> it);
assertThat(blocked[0], is(false));
}
Aggregations