use of cyclops.futurestream.LazyReact 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 cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazyToQueue method toQueue.
/*
* Populate provided queues with the sharded data from this Stream.
*
* @param shards Map of key to Queue shards
* @param sharder Sharding function, element to key converter
* @see com.oath.cyclops.react.stream.traits.ToQueue#toQueue(java.util.Map, java.util.function.Function)
*/
@Override
default <K> void toQueue(final Map<K, Queue<U>> shards, final Function<? super U, ? extends K> sharder) {
// in this case all the items have to be pushed to the shards,
// we can't rely on the client pulling them all to getValue them in to the right shards
final LazyReact service = getPopulator();
then(it -> shards.get(sharder.apply(it)).offer(it), service.getExecutor()).runThread(() -> {
shards.values().forEach(it -> it.close());
returnPopulator(service);
});
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class PushableStreamTest method testLazyFutureStream.
@Test
public void testLazyFutureStream() {
PushableFutureStream<Integer> pushable = StreamSource.ofUnbounded().futureStream(new LazyReact());
pushable.getInput().add(100);
pushable.getInput().close();
assertThat(pushable.getStream().collect(Collectors.toList()), hasItem(100));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class PushableStreamTest method testLazyFutureStreamAdapter.
@Test
public void testLazyFutureStreamAdapter() {
Signal<Integer> signal = Signal.queueBackedSignal();
FutureStream<Integer> pushable = StreamSource.futureStream(signal.getDiscrete(), new LazyReact());
signal.set(100);
signal.close();
assertThat(pushable.collect(Collectors.toList()), hasItem(100));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class PushableStreamTest method testMultiple.
@Test
public void testMultiple() {
MultipleStreamSource<Integer> multi = StreamSource.ofMultiple();
FutureStream<Integer> pushable = multi.futureStream(new LazyReact());
ReactiveSeq<Integer> seq = multi.reactiveSeq();
Stream<Integer> stream = multi.stream();
multi.getInput().offer(100);
multi.getInput().close();
Set<Integer> vals = new TreeSet<>();
pushable.forEach(vals::add);
seq.forEach(vals::add);
stream.forEach(vals::add);
assertThat(Sets.newSet(100), is(vals));
}
Aggregations