use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class PipesTest method futureStreamCustomTest.
@Test
public void futureStreamCustomTest() {
Pipes<String, Integer> bus = Pipes.of();
bus.register("reactor", QueueFactories.<Integer>boundedNonBlockingQueue(1000).build());
bus.publishTo("reactor", ReactiveSeq.of(10, 20, 30));
bus.close("reactor");
System.out.println(Thread.currentThread().getId());
List<String> res = bus.futureStream("reactor", new LazyReact(10, 10)).toOptional().get().map(i -> "fan-out toNested handle blocking I/O:" + Thread.currentThread().getId() + ":" + i).toList();
System.out.println(res);
assertThat(res.size(), equalTo(3));
}
use of cyclops.futurestream.LazyReact in project cyclops by aol.
the class PipesTest method publishToTest.
@Test
public void publishToTest() {
Pipes<String, Integer> bus = Pipes.of();
bus.register("reactor", QueueFactories.<Integer>boundedNonBlockingQueue(1000).build());
bus.publishTo("reactor", Flux.just(10, 20, 30));
bus.close("reactor");
System.out.println(Thread.currentThread().getId());
List<String> res = bus.futureStream("reactor", new LazyReact()).toOptional().get().map(i -> "fan-out toNested handle blocking I/O:" + Thread.currentThread().getId() + ":" + i).toList();
System.out.println(res);
assertThat(res.size(), equalTo(3));
}
use of cyclops.futurestream.LazyReact 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 cyclops.futurestream.LazyReact 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 cyclops.futurestream.LazyReact in project cyclops by aol.
the class LazySeqAgronaTest 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()));
}
Aggregations