use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class BatchingInvestigationsTest method batchIssue.
@Test
public void batchIssue() throws InterruptedException {
Queue<String> queue = QueueFactories.<String>unboundedQueue().build();
new Thread(() -> {
for (int i = 0; i < 10; i++) {
queue.offer("New message " + i);
sleep(10000);
}
}).start();
queue.stream().groupedBySizeAndTime(10, 500, TimeUnit.MILLISECONDS).to(s -> new LazyReact(ThreadPools.getSequential()).fromStream(s)).async().peek(System.out::println).run();
while (true) {
}
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method oneOrError.
@Test
public void oneOrError() throws InterruptedException {
Queue q = new Queue<>();
pipes.register("hello", q);
pipes.push("hello", "world");
pipes.push("hello", "world2");
q.close();
assertThat(pipes.oneOrError("hello").toOptional().get(), equalTo("world"));
assertThat(pipes.oneOrError("hello").toOptional().get(), equalTo("world2"));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method nextValue.
@Test
public void nextValue() throws InterruptedException {
Queue q = new Queue<>();
pipes.register("hello", q);
pipes.push("hello", "world");
pipes.push("hello", "world2");
q.close();
Eval<Maybe<String>> nextValue = pipes.nextValue("hello");
int values = 0;
while (nextValue.get().isPresent()) {
System.out.println(values++);
}
assertThat(values, equalTo(2));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method oneValueOrErrorTryException.
@Test
public void oneValueOrErrorTryException() throws InterruptedException {
Queue q = new Queue<>();
pipes.register("hello", q);
pipes.push("hello", "world");
q.close();
assertThat(pipes.oneValueOrError("hello", Throwable.class), equalTo(Option.some(Try.success("world"))));
assertThat(pipes.oneValueOrError("hello", Throwable.class).toOptional().get().failureGet().orElse(null), instanceOf(NoSuchElementException.class));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method nextNull.
@Test
public void nextNull() throws InterruptedException {
Queue q = new Queue<>();
pipes.register("hello", q);
pipes.push("hello", "world");
pipes.push("hello", "world2");
q.close();
Eval<String> nextValue = pipes.nextOrNull("hello");
int values = 0;
while (nextValue.get() != null) {
System.out.println(values++);
}
assertThat(values, equalTo(2));
}
Aggregations