Search in sources :

Example 46 with LazyReact

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));
}
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) LazyReact(cyclops.futurestream.LazyReact) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Example 47 with LazyReact

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()));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Tuple2(cyclops.data.tuple.Tuple2) Queue(com.oath.cyclops.async.adapters.Queue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyReact(cyclops.futurestream.LazyReact) Arrays.asList(java.util.Arrays.asList) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 48 with LazyReact

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()));
    }
}
Also used : LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tuple2(cyclops.data.tuple.Tuple2) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 49 with LazyReact

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"));
    }
}
Also used : LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 50 with LazyReact

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()));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tuple2(cyclops.data.tuple.Tuple2) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Aggregations

LazyReact (cyclops.futurestream.LazyReact)60 Test (org.junit.Test)58 List (java.util.List)27 Assert.assertThat (org.junit.Assert.assertThat)25 Queue (com.oath.cyclops.async.adapters.Queue)21 Matchers.equalTo (org.hamcrest.Matchers.equalTo)21 Ignore (org.junit.Ignore)20 ReactiveSeq (cyclops.reactive.ReactiveSeq)19 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)19 QueueFactories (com.oath.cyclops.async.QueueFactories)17 Arrays.asList (java.util.Arrays.asList)16 Collectors (java.util.stream.Collectors)16 Matchers.is (org.hamcrest.Matchers.is)16 ArrayList (java.util.ArrayList)15 ForkJoinPool (java.util.concurrent.ForkJoinPool)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Tuple2 (cyclops.data.tuple.Tuple2)14 FutureStream (cyclops.futurestream.FutureStream)13 ThreadPools (com.oath.cyclops.react.ThreadPools)12 Tuple.tuple (cyclops.data.tuple.Tuple.tuple)12