Search in sources :

Example 11 with SimpleReact

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyReact(cyclops.futurestream.LazyReact) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertNotNull(org.junit.Assert.assertNotNull) SimpleReact(cyclops.futurestream.SimpleReact) Assert.assertTrue(org.junit.Assert.assertTrue) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) Test(org.junit.Test) Assert.assertEquals(org.junit.Assert.assertEquals) SimpleReact(cyclops.futurestream.SimpleReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 12 with SimpleReact

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));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) List(java.util.List) Iterator(java.util.Iterator) Ignore(org.junit.Ignore) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Example 13 with SimpleReact

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));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) List(java.util.List) Iterator(java.util.Iterator) Ignore(org.junit.Ignore) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) SimpleReact(cyclops.futurestream.SimpleReact) Test(org.junit.Test)

Example 14 with SimpleReact

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));
}
Also used : Arrays(java.util.Arrays) LazyReact(cyclops.futurestream.LazyReact) Matchers(org.mockito.Matchers) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BaseSimpleReactStream(com.oath.cyclops.types.futurestream.BaseSimpleReactStream) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) ExecutionException(java.util.concurrent.ExecutionException) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Stream(java.util.stream.Stream) ForkJoinPool(java.util.concurrent.ForkJoinPool) SimpleReact(cyclops.futurestream.SimpleReact) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) SimpleReact(cyclops.futurestream.SimpleReact) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with SimpleReact

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) {
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) HttpServer(io.vertx.core.http.HttpServer) Vertx(io.vertx.core.Vertx) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) Assert.assertThat(org.junit.Assert.assertThat) ReactiveSeq(cyclops.reactive.ReactiveSeq) Tuple.tuple(cyclops.data.tuple.Tuple.tuple) Queue(com.oath.cyclops.async.adapters.Queue) Ignore(org.junit.Ignore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SimpleReact(cyclops.futurestream.SimpleReact) HttpServerOptions(io.vertx.core.http.HttpServerOptions) WaitStrategy(com.oath.cyclops.async.wait.WaitStrategy) CompletableFuture(java.util.concurrent.CompletableFuture) LazyReact(cyclops.futurestream.LazyReact) SimpleReact(cyclops.futurestream.SimpleReact) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Vertx(io.vertx.core.Vertx) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SimpleReact (cyclops.futurestream.SimpleReact)71 Test (org.junit.Test)70 Assert.assertThat (org.junit.Assert.assertThat)54 Matchers.is (org.hamcrest.Matchers.is)52 List (java.util.List)50 ExecutionException (java.util.concurrent.ExecutionException)46 Collectors (java.util.stream.Collectors)36 Set (java.util.Set)33 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)31 Matchers.hasItem (org.hamcrest.Matchers.hasItem)30 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)25 Arrays (java.util.Arrays)24 CompletableFuture (java.util.concurrent.CompletableFuture)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 Stream (java.util.stream.Stream)21 LazyReact (cyclops.futurestream.LazyReact)20 BaseSimpleReactStream (com.oath.cyclops.types.futurestream.BaseSimpleReactStream)17 ArrayList (java.util.ArrayList)16 ForkJoinPool (java.util.concurrent.ForkJoinPool)16 Ignore (org.junit.Ignore)14