use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testSeparatedChains.
@Test
public void testSeparatedChains() {
// .split(2);
BaseSimpleReactStream<String> orgBuilder = new SimpleReact().ofAsync(() -> "Hello", () -> "World");
BaseSimpleReactStream builder = orgBuilder;
for (int i = 0; i < 1000; i++) {
builder = builder.then(input -> input + " " + counter++);
}
List<String> results = orgBuilder.block();
assertThat(results.get(0), is("Hello"));
List<String> completeResults = builder.block();
assertThat(completeResults.get(0).length(), greaterThan(100));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testBlockInterruption.
@Test
public void testBlockInterruption() {
final AtomicBoolean isRunning = new AtomicBoolean(true);
final CountDownLatch startBarier = new CountDownLatch(1);
final BaseSimpleReactStream<Integer> stage = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then((it) -> {
try {
Thread.sleep(it * 5000);
} catch (InterruptedException e) {
System.err.println("InterruptedException");
Thread.currentThread().interrupt();
}
return it * 100;
});
Thread t = new Thread(() -> {
while (isRunning.get()) {
// worker thread termination condition
startBarier.countDown();
try {
while (true) {
// random condition
stage.block();
// Thread.sleep(2 * 5000);
}
} catch (Exception e) {
System.err.println("InterruptedException " + e.getMessage());
}
}
});
t.start();
try {
startBarier.await();
isRunning.getAndSet(false);
t.interrupt();
t.join();
} catch (InterruptedException e) {
// you know I don't care
}
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method doOnEach.
@Test
public void doOnEach() {
String[] found = { "" };
String res = new SimpleReact().ofAsync(() -> "hello").peek(it -> {
found[0] = it;
}).then(it -> it + "!").block().firstValue(null);
assertThat(found[0], is("hello"));
assertThat(res, is("hello!"));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testThenNull.
@Test
public void testThenNull() {
List<String> result = new SimpleReact().ofAsync(() -> "World", () -> "Hello").then(in -> (String) null).block();
assertThat(result.size(), is(2));
assertThat(result.get(0), is(nullValue()));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class ReactPoolTest method testSyncrhonous.
@Test
public void testSyncrhonous() {
ReactPool<SimpleReact> pool = ReactPool.syncrhonousPool();
new SimpleReact().ofAsync(() -> populate(pool));
List<String> result = pool.react((sr) -> sr.ofAsync(() -> "hello", () -> "world").peek(System.out::println).block());
assertThat(result.size(), is(2));
}
Aggregations