use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqTest method zipFastSlow.
@Test
public void zipFastSlow() {
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 cyclops.futurestream.LazyReact in project cyclops by aol.
the class ConnectableTest method hotStreamConnect.
@Test
public void hotStreamConnect() throws InterruptedException {
for (int i = 0; i < 10; i++) {
System.out.println(i);
value = null;
CountDownLatch latch = new CountDownLatch(1);
new LazyReact().range(0, Integer.MAX_VALUE).limit(100).peek(v -> value = v).peek(v -> latch.countDown()).peek(System.out::println).hotStream(exec).connect().limit(100).runFuture(ForkJoinPool.commonPool(), s -> s.forEach(System.out::println));
latch.await();
assertTrue(value != null);
}
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class ConnectableTest method hotStreamConnectBlockingQueue.
@Test
public void hotStreamConnectBlockingQueue() throws InterruptedException {
value = null;
CountDownLatch latch = new CountDownLatch(1);
new LazyReact().range(0, Integer.MAX_VALUE).limit(1000).peek(v -> value = v).peek(v -> latch.countDown()).hotStream(exec).connect(new LinkedBlockingQueue<>()).limit(100).runFuture(ForkJoinPool.commonPool(), s -> s.forEach(System.out::println));
latch.await();
assertTrue(value != null);
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqObjectPoolingTest method shouldZipTwoInfiniteSequences.
@Test
@Ignore
public void shouldZipTwoInfiniteSequences() throws Exception {
final FutureStream<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1);
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()));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqObjectPoolingTest 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);
}
Aggregations