Search in sources :

Example 31 with LazyReact

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

the class ReverseTest method limitList.

@Test
public void limitList() throws InterruptedException {
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < 1000; i++) list.add(i);
    assertThat(new LazyReact().fromIterable(list).limit(100).peek(System.out::println).count(), equalTo(100L));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) ArrayList(java.util.ArrayList) DuplicationTest(cyclops.futurestream.react.lazy.DuplicationTest) Test(org.junit.Test)

Example 32 with LazyReact

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

the class LazySeqAutoOptimizeTest method longRunForEach.

@Test
public void longRunForEach() {
    new LazyReact().autoOptimizeOn().range(0, 1_000_000).map(i -> i + 2).map(i -> Thread.currentThread().getId()).forEach(a -> {
    });
    System.out.println("Finished!");
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyReact(cyclops.futurestream.LazyReact) Arrays.asList(java.util.Arrays.asList) FutureStream(cyclops.futurestream.FutureStream) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Test(org.junit.Test) Supplier(java.util.function.Supplier) Assert.assertEquals(org.junit.Assert.assertEquals) LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 33 with LazyReact

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

the class LazySeqAutoOptimizeTest method longRun.

@Test
public void longRun() {
    AtomicInteger count = new AtomicInteger(0);
    new LazyReact().autoOptimizeOn().range(0, 1_000_000).map(i -> i + 2).map(i -> Thread.currentThread().getId()).peek(i -> count.incrementAndGet()).runOnCurrent();
    System.out.println("Finished! " + count.get());
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) ReactiveSeq(cyclops.reactive.ReactiveSeq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LazyReact(cyclops.futurestream.LazyReact) Arrays.asList(java.util.Arrays.asList) FutureStream(cyclops.futurestream.FutureStream) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Test(org.junit.Test) Supplier(java.util.function.Supplier) Assert.assertEquals(org.junit.Assert.assertEquals) LazyReact(cyclops.futurestream.LazyReact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 34 with LazyReact

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

the class LazySeqObjectPoolingTest 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) 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 35 with LazyReact

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

the class LazySeqObjectPoolingTest method zipFastSlow.

@Test
public void zipFastSlow() {
    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) 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) Queue(com.oath.cyclops.async.adapters.Queue) 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