Search in sources :

Example 36 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class SyncZippingTest method testUnzip.

@Test
public void testUnzip() {
    Supplier<ReactiveSeq<Tuple2<Integer, String>>> s = () -> of(new Tuple2(1, "a"), new Tuple2(2, "b"), new Tuple2(3, "c"));
    Tuple2<ReactiveSeq<Integer>, ReactiveSeq<String>> u1 = ReactiveSeq.unzip(s.get());
    assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) ReactiveSeq(cyclops.reactive.ReactiveSeq) FluxReactiveSeq(cyclops.reactive.FluxReactiveSeq) Test(org.junit.Test)

Example 37 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class LazySeqTest method shouldZipFiniteWithInfiniteSeq.

@Test
public void shouldZipFiniteWithInfiniteSeq() throws Exception {
    ThreadPools.setUseCommon(false);
    final ReactiveSeq<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1).limit(5);
    // <-- MEMORY LEAK! - no auto-closing yet, so writes infinetely to it's async queue
    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()));
    ThreadPools.setUseCommon(true);
}
Also used : Arrays(java.util.Arrays) Tuple2(cyclops.data.tuple.Tuple2) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) Matchers.not(org.hamcrest.Matchers.not) FutureStream(cyclops.futurestream.FutureStream) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) 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) TimeUnit(java.util.concurrent.TimeUnit) ReactiveSeq(cyclops.reactive.ReactiveSeq) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) 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) Assert.assertEquals(org.junit.Assert.assertEquals) LazyReact(cyclops.futurestream.LazyReact) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 38 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class LazySeqTest 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 : Arrays(java.util.Arrays) Tuple2(cyclops.data.tuple.Tuple2) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) QueueFactories(com.oath.cyclops.async.QueueFactories) LazyReact(cyclops.futurestream.LazyReact) Matchers.not(org.hamcrest.Matchers.not) FutureStream(cyclops.futurestream.FutureStream) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) 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) TimeUnit(java.util.concurrent.TimeUnit) ReactiveSeq(cyclops.reactive.ReactiveSeq) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) 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) Assert.assertEquals(org.junit.Assert.assertEquals) LazyReact(cyclops.futurestream.LazyReact) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 39 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class LazySeqObjectPoolingTest method shouldZipFiniteWithInfiniteSeq.

@Test
public void shouldZipFiniteWithInfiniteSeq() throws Exception {
    ThreadPools.setUseCommon(false);
    final ReactiveSeq<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1).limit(5);
    // <-- MEMORY LEAK! - no auto-closing yet, so writes infinetely to it's async queue
    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()));
    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) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) 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) TimeUnit(java.util.concurrent.TimeUnit) ReactiveSeq(cyclops.reactive.ReactiveSeq) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) 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) Assert(org.junit.Assert) Signal(com.oath.cyclops.async.adapters.Signal) LazyReact(cyclops.futurestream.LazyReact) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 40 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class ZippingTest method testUnzip4.

@Test
public void testUnzip4() {
    Supplier<ReactiveSeq<Tuple4<Integer, String, Long, Character>>> s = () -> DuplicationTest.of(new Tuple4(1, "a", 2l, 'z'), new Tuple4(2, "b", 3l, 'y'), new Tuple4(3, "c", 4l, 'x'));
    Tuple4<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>, ReactiveSeq<Character>> u1 = ReactiveSeq.unzip4(s.get());
    assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
    assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
    assertTrue(u1._4().toList().containsAll(asList('z', 'y', 'x')));
}
Also used : Tuple4(cyclops.data.tuple.Tuple4) ReactiveSeq(cyclops.reactive.ReactiveSeq) Test(org.junit.Test) DuplicationTest(cyclops.futurestream.react.lazy.DuplicationTest)

Aggregations

ReactiveSeq (cyclops.reactive.ReactiveSeq)101 Test (org.junit.Test)91 Tuple3 (cyclops.data.tuple.Tuple3)33 Tuple4 (cyclops.data.tuple.Tuple4)33 Tuple2 (cyclops.data.tuple.Tuple2)31 FlowableReactiveSeq (cyclops.reactive.FlowableReactiveSeq)19 FluxReactiveSeq (cyclops.reactive.FluxReactiveSeq)18 Stream (java.util.stream.Stream)17 Collectors (java.util.stream.Collectors)16 FutureStream (cyclops.futurestream.FutureStream)12 QueueFactories (com.oath.cyclops.async.QueueFactories)11 Queue (com.oath.cyclops.async.adapters.Queue)11 LazyReact (cyclops.futurestream.LazyReact)11 Supplier (java.util.function.Supplier)10 Signal (com.oath.cyclops.async.adapters.Signal)9 List (java.util.List)9 Spouts (cyclops.reactive.Spouts)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Matchers.equalTo (org.hamcrest.Matchers.equalTo)8 Assert.assertThat (org.junit.Assert.assertThat)8