use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class ParallelReduceSeedTest method collectAsync3Fused.
@Test
public void collectAsync3Fused() {
Scheduler s = Schedulers.newParallel("test", 3);
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 collectAsync.
@Test
public void collectAsync() {
Scheduler s = Schedulers.newParallel("test", 3);
Supplier<List<Integer>> as = () -> new ArrayList<>();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 100000).hide().parallel(3).runOn(s).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).sequential().reduce(0, (a, b) -> a + b.size()).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 collectAsync2.
@Test
public void collectAsync2() {
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).hide().collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).sequential().reduce(0, (a, b) -> a + b.size()).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 ParallelFluxTest method parallelMode.
@Test
public void parallelMode() {
Flux<Integer> source = Flux.range(1, 1_000_000).hide();
int ncpu = Math.max(8, Runtime.getRuntime().availableProcessors());
for (int i = 1; i < ncpu + 1; i++) {
Scheduler scheduler = Schedulers.newParallel("test", i);
try {
Flux<Integer> result = ParallelFlux.from(source, i).runOn(scheduler).map(v -> v + 1).sequential();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
result.subscribe(ts);
ts.await(Duration.ofSeconds(10));
ts.assertSubscribed().assertValueCount(1_000_000).assertComplete().assertNoError();
} finally {
scheduler.dispose();
}
}
}
use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.
the class FluxWindowTimeoutTest method rejectedOnSubscription.
@Test
public void rejectedOnSubscription() {
Scheduler testScheduler = new Scheduler() {
@Override
public Disposable schedule(Runnable task) {
throw Exceptions.failWithRejected();
}
@Override
public Worker createWorker() {
return new Worker() {
@Override
public Disposable schedule(Runnable task) {
throw Exceptions.failWithRejected();
}
@Override
public void dispose() {
}
};
}
};
StepVerifier.create(Flux.range(1, 3).hide().windowTimeout(10, Duration.ofMillis(500), testScheduler)).expectNextCount(1).verifyError(RejectedExecutionException.class);
}
Aggregations