Search in sources :

Example 11 with Queue

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

the class BaseSeqTest method shard.

@Test
public void shard() {
    Map<Integer, Queue<Integer>> shards = new HashMap<>();
    shards.put(1, new Queue());
    shards.put(2, new Queue());
    shards.put(3, new Queue());
    shards.put(4, new Queue());
    shards.put(5, new Queue());
    shards.put(6, new Queue());
    for (int i = 0; i < 100; i++) assertThat(of(1, 2, 3, 4, 5, 6).shard(MapX.fromMap(shards), Function.identity()).size(), is(6));
}
Also used : HashMap(java.util.HashMap) Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 12 with Queue

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

the class PipesTest method oneValueOrErrorTry.

@Test
public void oneValueOrErrorTry() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    pipes.push("hello", "world2");
    q.close();
    assertThat(pipes.oneValueOrError("hello", Throwable.class).toOptional().get().get(), equalTo(Option.some("world")));
    assertThat(pipes.oneValueOrError("hello").toOptional().get().get(), equalTo(Option.some("world2")));
}
Also used : Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 13 with Queue

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

the class PipesTest method reactiveSeq.

@Test
public void reactiveSeq() throws InterruptedException {
    Queue q = new Queue<>();
    pipes.register("hello", q);
    pipes.push("hello", "world");
    q.close();
    assertThat(pipes.reactiveSeq("hello").toOptional().get().toList(), equalTo(Arrays.asList("world")));
}
Also used : Queue(com.oath.cyclops.async.adapters.Queue) Test(org.junit.Test)

Example 14 with Queue

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

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

the class SimpleReactStream method join.

/**
 * flatten nested SimpleReactStreams
 *
 * @param stream Stream to flatten
 * @return flattened Stream
 */
static <U, R> SimpleReactStream<R> join(final SimpleReactStream<BaseSimpleReactStream<U>> stream) {
    final Queue queue = stream.getQueueFactory().build();
    stream.then(it -> it.sync().then(in -> queue.offer(in))).allOf(it -> queue.close());
    return stream.fromStream(queue.stream(stream.getSubscription()));
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Blocker(com.oath.cyclops.react.collectors.lazy.Blocker) Tuple2(cyclops.data.tuple.Tuple2) java.util(java.util) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) LazyReact(cyclops.futurestream.LazyReact) FutureStream(cyclops.futurestream.FutureStream) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Tuple(cyclops.data.tuple.Tuple) FilteredExecutionPathException(com.oath.cyclops.internal.react.exceptions.FilteredExecutionPathException) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) StreamSupport(java.util.stream.StreamSupport) Collector(java.util.stream.Collector) EagerStreamWrapper(com.oath.cyclops.internal.react.stream.EagerStreamWrapper) ThrowsSoftened(com.oath.cyclops.util.ThrowsSoftened) Continueable(com.oath.cyclops.react.async.subscription.Continueable) Streams(cyclops.companion.Streams) Executor(java.util.concurrent.Executor) Predicate(java.util.function.Predicate) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) ReactiveSeq(cyclops.reactive.ReactiveSeq) StageWithResults(com.oath.cyclops.react.StageWithResults) Queue(com.oath.cyclops.async.adapters.Queue) Stream(java.util.stream.Stream) Status(com.oath.cyclops.react.Status) SimpleReact(cyclops.futurestream.SimpleReact) QueueFactory(com.oath.cyclops.async.adapters.QueueFactory) Queue(com.oath.cyclops.async.adapters.Queue)

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