use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class CaptureTest method captureErrorOnce.
@Test
public void captureErrorOnce() throws InterruptedException {
count = new AtomicInteger(0);
new SimpleReact().of("hello", "world").capture(e -> count.incrementAndGet()).peek(System.out::println).then(this::exception).peek(System.out::println).then(s -> "hello" + s).run();
Thread.sleep(500);
assertEquals(count.get(), 2);
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class IterationTest method testIterate.
@Test
public void testIterate() throws InterruptedException, ExecutionException {
List<Integer> list = Arrays.asList(1, 2, 3, 4);
List<String> strings = new SimpleReact().<Integer>from(list.iterator()).peek(it -> System.out.println(it)).then(it -> it * 100).then(it -> "*" + it).block();
assertThat(strings.size(), is(4));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class IterationTest method testReactWithCollection.
@Test
public void testReactWithCollection() throws InterruptedException, ExecutionException {
List<Integer> list = Arrays.asList(1, 2, 3, 4);
List<String> strings = new SimpleReact().<Integer>from(list).peek(it -> System.out.println(it)).then(it -> it * 100).then(it -> "*" + it).block();
assertThat(strings.size(), is(4));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testThenMixedTypes.
@Test
public void testThenMixedTypes() {
List list = new ArrayList();
Map responses = new HashMap();
responses.put("Hello", (byte) 4);
responses.put(list, true);
List<Object> result = new SimpleReact().ofAsync(() -> "Hello", () -> list).then(it -> responses.get(it)).block();
assertThat(result.size(), is(2));
assertThat(result, hasItem((byte) 4));
assertThat(result, hasItem(true));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class VertxTest method httpServer.
@Test
@Ignore
public void httpServer() {
Vertx vertx = Vertx.factory.vertx();
CompletableFuture<HttpServer> server = new CompletableFuture<>();
Queue<HttpServerRequest> reqs = QueueFactories.<HttpServerRequest>boundedNonBlockingQueue(1000, WaitStrategy.spinWait()).build();
vertx.createHttpServer(new HttpServerOptions().setPort(8080).setHost("localhost")).requestHandler(event -> {
reqs.add(event);
System.out.println(event.absoluteURI());
}).listen(e -> {
if (e.succeeded())
server.complete(e.result());
else
server.completeExceptionally(e.cause());
});
LazyReact react = new LazyReact(c -> vertx.runOnContext(v -> c.run()));
react.fromStream(reqs.stream()).filter(req -> req.getParam("num") != null).peek(i -> System.out.println("grouping " + i)).grouped(2).map(list -> tuple(list.getOrElse(0, null).response(), list.getOrElse(1, null).response(), getParam(list.getOrElse(0, null)), getParam(list.getOrElse(1, null)))).peek(i -> System.out.println("peeking + " + i)).peek(t -> t._1().end("adding " + (t._3() + t._4()))).peek(t -> t._2().end("multiplying " + t._3() * t._4())).run();
new SimpleReact(c -> vertx.runOnContext(v -> c.run())).from(server).then(s -> "server started").onFail(e -> "failed toNested skip " + e.getMessage()).peek(System.out::println);
while (true) {
}
}
Aggregations