Search in sources :

Example 6 with FutureStream

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

the class BaseSeqTest method asyncSyncTest.

@Test
public void asyncSyncTest() {
    FutureStream stream = of(1, 2, 3, 4).async().sync();
    assertThat(stream.isAsync(), is(false));
}
Also used : FutureStream(cyclops.futurestream.FutureStream) Test(org.junit.Test)

Example 7 with FutureStream

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

the class BaseSeqTest method syncTest.

@Test
public void syncTest() {
    FutureStream stream = of(1, 2, 3, 4).sync();
    assertThat(stream.isAsync(), is(false));
}
Also used : FutureStream(cyclops.futurestream.FutureStream) Test(org.junit.Test)

Example 8 with FutureStream

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

the class BaseSeqTest method syncAndAsyncTest.

@Test
public void syncAndAsyncTest() {
    FutureStream stream = of(1, 2, 3, 4).sync().async();
    assertThat(stream.isAsync(), is(true));
}
Also used : FutureStream(cyclops.futurestream.FutureStream) Test(org.junit.Test)

Example 9 with FutureStream

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

the class LazyToQueue method addToQueue.

@Override
default void addToQueue(final Queue queue) {
    FutureStream str = thenSync(queue::add).self(s -> {
        if (this.getPopulator().isPoolingActive())
            s.peekSync(v -> {
                throw new CompletedException(v);
            });
    });
    final Continuation continuation = queue.getContinuationStrategy().isBlocking() ? str.blockingContinuation(() -> {
        throw new ClosedQueueException();
    }) : str.runContinuation(() -> {
        throw new ClosedQueueException();
    });
    queue.addContinuation(continuation);
}
Also used : Consumer(java.util.function.Consumer) Queue(com.oath.cyclops.async.adapters.Queue) ClosedQueueException(com.oath.cyclops.async.adapters.Queue.ClosedQueueException) Executor(java.util.concurrent.Executor) LazyReact(cyclops.futurestream.LazyReact) Map(java.util.Map) FutureStream(cyclops.futurestream.FutureStream) CompletedException(com.oath.cyclops.internal.react.async.future.CompletedException) Function(java.util.function.Function) CompletedException(com.oath.cyclops.internal.react.async.future.CompletedException) ClosedQueueException(com.oath.cyclops.async.adapters.Queue.ClosedQueueException) FutureStream(cyclops.futurestream.FutureStream)

Example 10 with FutureStream

use of cyclops.futurestream.FutureStream 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)

Aggregations

FutureStream (cyclops.futurestream.FutureStream)31 Test (org.junit.Test)27 Tuple2 (cyclops.data.tuple.Tuple2)19 Stream (java.util.stream.Stream)17 BaseSeqTest (cyclops.futurestream.react.base.BaseSeqTest)16 LazyReact (cyclops.futurestream.LazyReact)12 Queue (com.oath.cyclops.async.adapters.Queue)11 ReactiveSeq (cyclops.reactive.ReactiveSeq)11 Collectors (java.util.stream.Collectors)11 QueueFactories (com.oath.cyclops.async.QueueFactories)8 Collection (java.util.Collection)8 Signal (com.oath.cyclops.async.adapters.Signal)7 ThreadPools (com.oath.cyclops.react.ThreadPools)7 Tuple.tuple (cyclops.data.tuple.Tuple.tuple)7 Serializable (java.io.Serializable)7 Arrays.asList (java.util.Arrays.asList)7 List (java.util.List)6 ForkJoinPool (java.util.concurrent.ForkJoinPool)6 Matchers.is (org.hamcrest.Matchers.is)6 Ignore (org.junit.Ignore)6