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));
}
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")));
}
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")));
}
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);
}
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()));
}
Aggregations