Search in sources :

Example 36 with Scheduler

use of reactor.core.scheduler.Scheduler in project reactor-core by reactor.

the class ParallelMergeReduceTest method parallelReduceFull.

@Test
public void parallelReduceFull() {
    int m = 100_000;
    for (int n = 1; n <= m; n *= 10) {
        // System.out.println(n);
        for (int i = 1; i <= Runtime.getRuntime().availableProcessors(); i++) {
            // System.out.println("  " + i);
            Scheduler scheduler = Schedulers.newParallel("test", i);
            try {
                AssertSubscriber<Long> ts = AssertSubscriber.create();
                Flux.range(1, n).map(v -> (long) v).parallel(i).runOn(scheduler).reduce((a, b) -> a + b).subscribe(ts);
                ts.await(Duration.ofSeconds(500));
                long e = ((long) n) * (1 + n) / 2;
                ts.assertValues(e);
            } finally {
                scheduler.dispose();
            }
        }
    }
}
Also used : CoreSubscriber(reactor.core.CoreSubscriber) Scannable(reactor.core.Scannable) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Schedulers(reactor.core.scheduler.Schedulers) Test(org.junit.Test) MergeReduceInner(reactor.core.publisher.ParallelMergeReduce.MergeReduceInner) Scheduler(reactor.core.scheduler.Scheduler) MergeReduceMain(reactor.core.publisher.ParallelMergeReduce.MergeReduceMain) Scheduler(reactor.core.scheduler.Scheduler) Test(org.junit.Test)

Aggregations

Scheduler (reactor.core.scheduler.Scheduler)36 Test (org.junit.Test)35 Schedulers (reactor.core.scheduler.Schedulers)19 Duration (java.time.Duration)17 List (java.util.List)16 CountDownLatch (java.util.concurrent.CountDownLatch)16 StepVerifier (reactor.test.StepVerifier)16 ArrayList (java.util.ArrayList)15 AssertSubscriber (reactor.test.subscriber.AssertSubscriber)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 CoreSubscriber (reactor.core.CoreSubscriber)13 Arrays (java.util.Arrays)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 TimeUnit (java.util.concurrent.TimeUnit)11 Subscription (org.reactivestreams.Subscription)11 Scannable (reactor.core.Scannable)11 Assert (org.junit.Assert)10 Publisher (org.reactivestreams.Publisher)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Disposable (reactor.core.Disposable)7