use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class VertxTest method sum.
@Test
public void sum() {
Vertx vertx = Vertx.factory.vertx();
LazyReact react = new LazyReact(c -> vertx.runOnContext(v -> c.run()));
int number = react.of(1, 2, 3).map(i -> i + 1).reduce((a, b) -> a + b).orElse(Integer.MIN_VALUE);
// 2 + 3 + 4 = 9
System.out.println("sum = " + number);
assertThat(number, equalTo(9));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoclosingTest method autoClosingLimit2Limit1.
@Test
public void autoClosingLimit2Limit1() throws InterruptedException {
System.out.println("Last test!!");
close = new AtomicInteger();
added = new AtomicInteger();
// subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
List<String> results = new LazyReact().generateAsync(() -> nextValues()).withQueueFactory(() -> eventQueue()).flatMap(list -> list.stream()).peek(System.out::println).limit(2).flatMap(list -> list.stream()).peek(System.out::println).limit(1).collect(Collectors.toList());
System.out.println("finished");
Thread.sleep(1000);
int localAdded = added.get();
assertThat(close.get(), greaterThan(0));
assertThat(results.size(), is(1));
assertThat(localAdded, is(added.get()));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoclosingTest method autoClosingZipLots.
@Test
public void autoClosingZipLots() throws InterruptedException {
for (int i = 0; i < 1500; i++) {
close = new AtomicInteger();
added = new AtomicInteger();
// subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
List<Tuple2<List<List<String>>, Integer>> results = new LazyReact().generate(() -> nextValues()).withQueueFactory(() -> eventQueue()).zip(new LazyReact().of(1, 2, 3)).collect(Collectors.toList());
System.out.println("finished");
int localAdded = added.get();
assertThat(close.get(), greaterThan(0));
assertThat(results.size(), is(3));
assertThat(localAdded, is(added.get()));
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoclosingTest method autoClosingLimit2Limit1Lots.
@Test
public void autoClosingLimit2Limit1Lots() throws InterruptedException {
for (int i = 0; i < 1500; i++) {
close = new AtomicInteger();
added = new AtomicInteger();
System.out.println("test " + i);
// subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
List<String> results = new LazyReact().generateAsync(() -> nextValues()).withQueueFactory(() -> eventQueue()).flatMap(list -> list.stream()).peek(System.out::println).actOnFutures().limit(2).flatMap(list -> list.stream()).peek(System.out::println).actOnFutures().limit(1).collect(Collectors.toList());
if (results.size() != 1)
System.out.println("hello world!");
assertThat(results.size(), is(1));
assertThat(results.get(0), is("1"));
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class AutoclosingTest method autoClosingZip.
@Test
public void autoClosingZip() throws InterruptedException {
System.out.println("Started!");
close = new AtomicInteger();
added = new AtomicInteger();
// subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
List<Tuple2<List<List<String>>, Integer>> results = new LazyReact().generateAsync(() -> nextValues()).withQueueFactory(() -> eventQueue()).zip(new LazyReact().of(1, 2, 3)).collect(Collectors.toList());
System.out.println("finished");
int localAdded = added.get();
assertThat(close.get(), greaterThan(0));
assertThat(results.size(), is(3));
assertThat(localAdded, is(added.get()));
}
Aggregations