use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class FluxTests method testParallelWithJava8StreamsInput.
/**
* https://gist.github.com/nithril/444d8373ce67f0a8b853 Contribution by Nicolas Labrot
* @throws InterruptedException on interrupt
*/
@Test
public void testParallelWithJava8StreamsInput() throws InterruptedException {
Scheduler supplier = Schedulers.newParallel("test-p", 2);
int max = ThreadLocalRandom.current().nextInt(100, 300);
CountDownLatch countDownLatch = new CountDownLatch(max);
Flux<Integer> worker = Flux.range(0, max).publishOn(asyncGroup);
worker.parallel(2).runOn(supplier).map(v -> v).subscribe(v -> countDownLatch.countDown());
countDownLatch.await(10, TimeUnit.SECONDS);
Assert.assertEquals(0, countDownLatch.getCount());
}
use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class FluxBlackboxProcessorVerification method transformFlux.
@Override
Flux<Integer> transformFlux(Flux<Integer> f) {
Flux<String> otherStream = Flux.just("test", "test2", "test3");
// System.out.println("Providing new downstream");
Scheduler asyncGroup = Schedulers.newParallel("flux-p-tck", 2);
BiFunction<Integer, String, Integer> combinator = (t1, t2) -> t1;
return f.publishOn(sharedGroup).parallel(2).groups().flatMap(stream -> stream.publishOn(asyncGroup).doOnNext(this::monitorThreadUse).scan((prev, next) -> next).map(integer -> -integer).filter(integer -> integer <= 0).map(integer -> -integer).bufferTimeout(batch, Duration.ofMillis(50)).flatMap(Flux::fromIterable).flatMap(i -> Flux.zip(Flux.just(i), otherStream, combinator))).publishOn(sharedGroup).doAfterTerminate(asyncGroup::dispose).doOnError(Throwable::printStackTrace);
}
use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class ParallelReduceSeedTest method collectAsync3Take.
@Test
public void collectAsync3Take() {
Scheduler s = Schedulers.newParallel("test", 4);
Supplier<List<Integer>> as = () -> new ArrayList<>();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 100000).publishOn(s).parallel(3).runOn(s).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).groups().flatMap(v -> v).reduce(0, (a, b) -> b.size() + a).subscribe(ts);
ts.await(Duration.ofSeconds(5));
ts.assertValues(100_000).assertNoError().assertComplete();
}
use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class ParallelReduceSeedTest method collectAsync3.
@Test
public void collectAsync3() {
Scheduler s = Schedulers.newParallel("test", 3);
Supplier<List<Integer>> as = () -> new ArrayList<>();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 100000).hide().publishOn(s).parallel(3).runOn(s).filter(t -> true).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).groups().flatMap(v -> v).reduce(0, (a, b) -> b.size() + a).subscribe(ts);
ts.await(Duration.ofSeconds(5));
ts.assertValues(100_000).assertNoError().assertComplete();
}
use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class ParallelReduceSeedTest method collectAsyncFused.
@Test
public void collectAsyncFused() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Scheduler scheduler = Schedulers.newParallel("test", 3);
Flux.range(1, 100000).parallel(3).runOn(scheduler).collect(ArrayList::new, ArrayList::add).sequential().reduce(0, (a, b) -> a + b.size()).subscribe(ts);
ts.await(Duration.ofSeconds(5));
ts.assertValues(100_000).assertNoError().assertComplete();
}
Aggregations