use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method nextAsync.
@Test
public void nextAsync() {
Queue q = new Queue<>();
pipes.register("hello", q);
pipes.push("hello", "world");
pipes.push("hello", "world2");
q.close();
assertThat(pipes.oneOrErrorAsync("hello", ex).get(), equalTo(Future.ofResult("world").get()));
assertThat(pipes.oneOrErrorAsync("hello", ex).get(), equalTo(Future.ofResult("world2").get()));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method publishTo.
@Test
public void publishTo() throws InterruptedException {
Pipes<String, Integer> pipes = Pipes.of();
Queue queue = new Queue();
pipes.register("hello", queue);
pipes.publishToAsync("hello", LazyReact.sequentialBuilder().of(1, 2, 3));
Thread.sleep(100);
queue.offer(4);
queue.close();
assertThat(queue.stream().toList(), equalTo(Arrays.asList(1, 2, 3, 4)));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class AutoclosingTest method autoClosingLimit2Limit1.
@Test
public void autoClosingLimit2Limit1() throws InterruptedException {
System.out.println("Last test!!");
close = new AtomicInteger();
added = new AtomicInteger();
// subscription fills from outside in (lazyRight to lazyLeft), need to store open / closed for each queue
List<String> results = new LazyReact().generateAsync(() -> nextValues()).withQueueFactory(() -> eventQueue()).flatMap(list -> list.stream()).peek(System.out::println).limit(2).flatMap(list -> list.stream()).peek(System.out::println).limit(1).collect(Collectors.toList());
System.out.println("finished");
Thread.sleep(1000);
int localAdded = added.get();
assertThat(close.get(), greaterThan(0));
assertThat(results.size(), is(1));
assertThat(localAdded, is(added.get()));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class LazySeqAgronaTest 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);
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class LazySeqAgronaTest method testBackPressureWhenZippingUnevenStreams2.
@Test
public void testBackPressureWhenZippingUnevenStreams2() {
Queue fast = LazyReact.parallelBuilder().withExecutor(new ForkJoinPool(2)).generateAsync(() -> "100").withQueueFactory(QueueFactories.boundedQueue(10)).toQueue();
new Thread(() -> {
LazyReact.parallelBuilder().withExecutor(new ForkJoinPool(2)).range(0, 1000).peek(c -> sleep(10)).zip(fast.stream()).forEach(it -> {
});
}).start();
;
fast.setSizeSignal(Signal.queueBackedSignal());
int max = fast.getSizeSignal().getContinuous().stream().mapToInt(it -> (int) it).limit(50).max().getAsInt();
assertThat(max, lessThan(11));
}
Aggregations