Search in sources :

Example 11 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class PipesTest method futureStreamCustomTest.

@Test
public void futureStreamCustomTest() {
    Pipes<String, Integer> bus = Pipes.of();
    bus.register("reactor", QueueFactories.<Integer>boundedNonBlockingQueue(1000).build());
    bus.publishTo("reactor", ReactiveSeq.of(10, 20, 30));
    bus.close("reactor");
    System.out.println(Thread.currentThread().getId());
    List<String> res = bus.futureStream("reactor", new LazyReact(10, 10)).toOptional().get().map(i -> "fan-out toNested handle blocking I/O:" + Thread.currentThread().getId() + ":" + i).toList();
    System.out.println(res);
    assertThat(res.size(), equalTo(3));
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Arrays(java.util.Arrays) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) NoSuchElementException(java.util.NoSuchElementException) Pipes(cyclops.futurestream.Pipes) Before(org.junit.Before) cyclops.control(cyclops.control) Executor(java.util.concurrent.Executor) lombok.val(lombok.val) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Executors(java.util.concurrent.Executors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) ForkJoinPool(java.util.concurrent.ForkJoinPool) Matchers.equalTo(org.hamcrest.Matchers.equalTo) QueueBasedSubscriber(com.oath.cyclops.types.reactive.QueueBasedSubscriber) LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 12 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class PipesTest method publishToTest.

@Test
public void publishToTest() {
    Pipes<String, Integer> bus = Pipes.of();
    bus.register("reactor", QueueFactories.<Integer>boundedNonBlockingQueue(1000).build());
    bus.publishTo("reactor", Flux.just(10, 20, 30));
    bus.close("reactor");
    System.out.println(Thread.currentThread().getId());
    List<String> res = bus.futureStream("reactor", new LazyReact()).toOptional().get().map(i -> "fan-out toNested handle blocking I/O:" + Thread.currentThread().getId() + ":" + i).toList();
    System.out.println(res);
    assertThat(res.size(), equalTo(3));
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Arrays(java.util.Arrays) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) NoSuchElementException(java.util.NoSuchElementException) Pipes(cyclops.futurestream.Pipes) Before(org.junit.Before) cyclops.control(cyclops.control) Executor(java.util.concurrent.Executor) lombok.val(lombok.val) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Executors(java.util.concurrent.Executors) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) List(java.util.List) Queue(com.oath.cyclops.async.adapters.Queue) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) ForkJoinPool(java.util.concurrent.ForkJoinPool) Matchers.equalTo(org.hamcrest.Matchers.equalTo) QueueBasedSubscriber(com.oath.cyclops.types.reactive.QueueBasedSubscriber) LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 13 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class AutoclosingTest method autoClosingLimit1.

@Test
public void autoClosingLimit1() throws InterruptedException {
    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).flatMap(list -> list.stream()).peek(System.out::println).limit(1).collect(Collectors.toList());
    System.out.println("finished");
    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 14 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class AutoclosingTest method autoClosingIterate.

@Test
public void autoClosingIterate() 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<Integer> results = new LazyReact().iterate(0, val -> val + 1).withQueueFactory(() -> eventQueueInts()).flatMap(val -> asList(asList(val, 1, 2, 3)).stream()).peek(System.out::println).limit(2).flatMap(list -> list.stream()).peek(System.out::println).limit(1).collect(Collectors.toList());
    System.out.println("finished");
    int localAdded = added.get();
    assertThat(close.get(), greaterThan(0));
    assertThat(results.size(), is(1));
    assertThat(localAdded, is(added.get()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 15 with LazyReact

use of cyclops.futurestream.LazyReact in project cyclops by aol.

the class LazySeqAgronaTest method shouldZipTwoInfiniteSequences.

@Test
@Ignore
public void shouldZipTwoInfiniteSequences() throws Exception {
    final FutureStream<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1);
    final FutureStream<Integer> hundreds = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(100, n -> n + 100);
    final ReactiveSeq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p);
    assertThat(zipped.limit(5).join(), equalTo(of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join()));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) Ignore(org.junit.Ignore) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) 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