Search in sources :

Example 1 with LazyReact

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

the class AnyJavaslangMTest method javaslangCyclops.

@Test
public void javaslangCyclops() {
    Lists.forEach2(List.of(1, 2, 3), a -> List.range(0, a), this::add);
    Options.forEach2(Option.none(), a -> Option.<Integer>some(a + 1), this::add);
    Option.some(1).flatMap(a -> Option.some(a + 1).map(b -> add(a, b)));
    Array.of(1, 2, 3, 4).flatMap(i -> new LazyReact().range(i, 10)).forEach(System.out::println);
    ReactiveSeq.of(1, 2, 3, 4).concatMap(i -> Stream.iterate(1, a -> a + 1).take(i)).map(i -> i + 2);
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Arrays(java.util.Arrays) Vavr(cyclops.monads.Vavr) Queue(io.vavr.collection.Queue) LazyReact(cyclops.futurestream.LazyReact) Lists(cyclops.companion.vavr.Lists) Function(java.util.function.Function) List(io.vavr.collection.List) Assert.assertThat(org.junit.Assert.assertThat) Option(io.vavr.control.Option) HashSet(io.vavr.collection.HashSet) Future(io.vavr.concurrent.Future) Options(cyclops.companion.vavr.Options) AnyM(cyclops.monads.AnyM) Stream(io.vavr.collection.Stream) Vector(io.vavr.collection.Vector) Trys(cyclops.companion.vavr.Trys) Array(io.vavr.collection.Array) Test(org.junit.Test) Transformable(com.oath.cyclops.types.functor.Transformable) CharSeq(io.vavr.collection.CharSeq) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ReactiveSeq(cyclops.reactive.ReactiveSeq) Try(io.vavr.control.Try) Either(io.vavr.control.Either) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SortedSetX(cyclops.reactive.collections.mutable.SortedSetX) Data(lombok.Data) LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 2 with LazyReact

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

the class ReactPoolTest method testUnbounded.

@Test
public void testUnbounded() {
    ReactPool<LazyReact> pool = ReactPool.unboundedPool(asList(new LazyReact(), new LazyReact()));
    List<String> result = pool.react((er) -> er.ofAsync(() -> "hello", () -> "world").block());
    pool.populate(new LazyReact());
    assertThat(result.size(), is(2));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 3 with LazyReact

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

the class PushableStreamTest method testLazyFutureStreamTopicQueueFactory.

@Test
public void testLazyFutureStreamTopicQueueFactory() {
    MultipleStreamSource<Integer> multi = StreamSource.ofMultiple(QueueFactories.boundedQueue(100));
    FutureStream<Integer> pushable = multi.futureStream(new LazyReact());
    multi.getInput().offer(100);
    multi.getInput().close();
    assertThat(pushable.collect(Collectors.toList()), hasItem(100));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 4 with LazyReact

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

the class PushableStreamTest method testLazyFutureStreamTopic.

@Test
public void testLazyFutureStreamTopic() {
    MultipleStreamSource<Integer> multi = StreamSource.ofMultiple();
    FutureStream<Integer> pushable = multi.futureStream(new LazyReact());
    multi.getInput().offer(100);
    multi.getInput().close();
    assertThat(pushable.collect(Collectors.toList()), hasItem(100));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) Test(org.junit.Test)

Example 5 with LazyReact

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

the class PushableStreamTest method testLazyFutureStreamTopicBackPressure.

@Test
public void testLazyFutureStreamTopicBackPressure() {
    MultipleStreamSource<Integer> multi = StreamSource.ofMultiple(2);
    FutureStream<Integer> pushable = multi.futureStream(new LazyReact());
    multi.getInput().offer(100);
    multi.getInput().close();
    assertThat(pushable.collect(Collectors.toList()), hasItem(100));
}
Also used : LazyReact(cyclops.futurestream.LazyReact) 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