use of cyclops.futurestream.FutureStream in project cyclops by aol.
the class LazySeqObjectPoolingTest method testZipWithFuturesStream.
@Test
public void testZipWithFuturesStream() {
Stream stream = of("a", "b");
FutureStream<Tuple2<Integer, String>> seq = of(1, 2).actOnFutures().zip(stream);
// .map(tuple -> Tuple.tuple(tuple.v1.join(),tuple.v2)).collect(CyclopsCollectors.toList());
List<Tuple2<Integer, String>> result = seq.block();
assertThat(result.size(), is(asList(tuple(1, "a"), tuple(2, "b")).size()));
}
use of cyclops.futurestream.FutureStream 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);
}
use of cyclops.futurestream.FutureStream in project cyclops by aol.
the class ParallelTest method runThread.
@Test
public void runThread() {
CompletableFuture cf = new CompletableFuture();
FutureStream s = LazyReact.sequentialBuilder().withMaxActive(MaxActive.IO).async().generateAsync(() -> 1).limit(1_000_000);
for (int x = 0; x < 60; x++) {
s = s.then(Function.identity());
}
// s.runOnCurrent();
s.runThread(() -> cf.complete(true));
cf.join();
}
use of cyclops.futurestream.FutureStream in project cyclops by aol.
the class LazySeqObjectPoolingTest 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);
}
use of cyclops.futurestream.FutureStream in project cyclops by aol.
the class LazySeqObjectPoolingTest method testZipWithFutures.
@Test
public void testZipWithFutures() {
FutureStream stream = of("a", "b");
FutureStream<Tuple2<Integer, String>> seq = of(1, 2).actOnFutures().zip(stream);
// .map(tuple -> Tuple.tuple(tuple.v1.join(),tuple.v2)).collect(CyclopsCollectors.toList());
List<Tuple2<Integer, String>> result = seq.block();
assertThat(result.size(), is(asList(tuple(1, "a"), tuple(2, "b")).size()));
}
Aggregations