use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class PipesTest method xValues.
@Test
public void xValues() throws InterruptedException {
Queue q = new Queue<>();
pipes.register("hello", q);
pipes.push("hello", "world");
pipes.push("hello", "world2");
pipes.push("hello", "world3");
pipes.push("hello", "world4");
q.close();
assertThat(pipes.xValues("hello", 2), equalTo(ListX.of("world", "world2")));
assertThat(pipes.xValues("hello", 2), equalTo(ListX.of("world3", "world4")));
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class AutoclosingTest method autoClosingLimit1.
@Test
public void autoClosingLimit1() throws InterruptedException {
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).flatMap(list -> list.stream()).peek(System.out::println).limit(1).collect(Collectors.toList());
System.out.println("finished");
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 AutoclosingTest method autoClosingIterate.
@Test
public void autoClosingIterate() 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<Integer> results = new LazyReact().iterate(0, val -> val + 1).withQueueFactory(() -> eventQueueInts()).flatMap(val -> asList(asList(val, 1, 2, 3)).stream()).peek(System.out::println).limit(2).flatMap(list -> list.stream()).peek(System.out::println).limit(1).collect(Collectors.toList());
System.out.println("finished");
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 zipFastSlow.
@Test
public void zipFastSlow() {
FutureStream<Integer> s;
Queue q = new Queue();
LazyReact.parallelBuilder().generate(() -> sleep(100)).then(it -> q.add("100")).runThread(new Thread());
new LazyReact().of(1, 2, 3, 4, 5, 6).zip(q.stream()).peek(it -> System.out.println(it)).collect(Collectors.toList());
}
use of com.oath.cyclops.async.adapters.Queue in project cyclops by aol.
the class LazySeqAgronaTest method shouldZipInfiniteWithFiniteSeq.
@Test
public void shouldZipInfiniteWithFiniteSeq() throws Exception {
ThreadPools.setUseCommon(false);
// <-- MEMORY LEAK!- no auto-closing yet, so writes infinetely to it's async queue
final FutureStream<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1);
final ReactiveSeq<Integer> hundreds = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(100, n -> n + 100).limit(5);
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);
}
Aggregations