Search in sources :

Example 6 with Queue

use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.

the class PipesTest method xValues.

@Test
public void xValues() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    pipes.push("hello", "world2");
    pipes.push("hello", "world3");
    pipes.push("hello", "world4");
    q.close();
    assertThat(pipes.xValues("hello", 2), equalTo(ListX.of("world", "world2")));
    assertThat(pipes.xValues("hello", 2), equalTo(ListX.of("world3", "world4")));
}
Also used : Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 7 with Queue

use of com.oath.cyclops.async.adapters.Queue 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 8 with Queue

use of com.oath.cyclops.async.adapters.Queue 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 9 with Queue

use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.

the class LazySeqAgronaTest method zipFastSlow.

@Test
public void zipFastSlow() {
    FutureStream<Integer> s;
    Queue q = new Queue();
    LazyReact.parallelBuilder().generate(() -> sleep(100)).then(it -> q.add("100")).runThread(new Thread());
    new LazyReact().of(1, 2, 3, 4, 5, 6).zip(q.stream()).peek(it -> System.out.println(it)).collect(Collectors.toList());
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) Matchers.not(org.hamcrest.Matchers.not) FutureStream(cyclops.futurestream.FutureStream) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) Tuple.tuple(cyclops.data.tuple.Tuple.tuple) Arrays.asList(java.util.Arrays.asList) Matchers.lessThan(org.hamcrest.Matchers.lessThan) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Iterator(java.util.Iterator) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ReactiveSeq(cyclops.reactive.ReactiveSeq) List(java.util.List) Stream(java.util.stream.Stream) Queue(com.oath.cyclops.async.adapters.Queue) Ignore(org.junit.Ignore) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ForkJoinPool(java.util.concurrent.ForkJoinPool) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ThreadPools(com.oath.cyclops.react.ThreadPools) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Signal(com.oath.cyclops.async.adapters.Signal) LazyReact(cyclops.futurestream.LazyReact) Queue(com.oath.cyclops.async.adapters.Queue) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 10 with Queue

use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.

the class LazySeqAgronaTest method shouldZipInfiniteWithFiniteSeq.

@Test
public void shouldZipInfiniteWithFiniteSeq() throws Exception {
    ThreadPools.setUseCommon(false);
    // <-- MEMORY LEAK!- no auto-closing yet, so writes infinetely to it's async queue
    final FutureStream<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1);
    final ReactiveSeq<Integer> hundreds = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(100, n -> n + 100).limit(5);
    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()));
    ThreadPools.setUseCommon(true);
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) Matchers.not(org.hamcrest.Matchers.not) FutureStream(cyclops.futurestream.FutureStream) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) Tuple.tuple(cyclops.data.tuple.Tuple.tuple) Arrays.asList(java.util.Arrays.asList) Matchers.lessThan(org.hamcrest.Matchers.lessThan) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Iterator(java.util.Iterator) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ReactiveSeq(cyclops.reactive.ReactiveSeq) List(java.util.List) Stream(java.util.stream.Stream) Queue(com.oath.cyclops.async.adapters.Queue) Ignore(org.junit.Ignore) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ForkJoinPool(java.util.concurrent.ForkJoinPool) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ThreadPools(com.oath.cyclops.react.ThreadPools) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Signal(com.oath.cyclops.async.adapters.Signal) LazyReact(cyclops.futurestream.LazyReact) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Aggregations

Queue (com.oath.cyclops.async.adapters.Queue)68 Test (org.junit.Test)52 List (java.util.List)34 ArrayList (java.util.ArrayList)28 Collectors (java.util.stream.Collectors)25 Stream (java.util.stream.Stream)23 LazyReact (cyclops.futurestream.LazyReact)22 InternalEvent (com.nextdoor.bender.InternalEvent)18 OperationProcessor (com.nextdoor.bender.operation.OperationProcessor)18 QueueFactories (com.oath.cyclops.async.QueueFactories)17 Tuple2 (cyclops.data.tuple.Tuple2)17 Iterator (java.util.Iterator)17 ReactiveSeq (cyclops.reactive.ReactiveSeq)16 Ignore (org.junit.Ignore)16 FutureStream (cyclops.futurestream.FutureStream)15 Arrays.asList (java.util.Arrays.asList)15 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)15 Matchers.is (org.hamcrest.Matchers.is)15 ThreadPools (com.oath.cyclops.react.ThreadPools)14 Tuple.tuple (cyclops.data.tuple.Tuple.tuple)14