Search in sources :

Example 11 with Scheduler

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();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 12 with Scheduler

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();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 13 with Scheduler

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();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

Example 14 with Scheduler

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();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) TestPublisher(reactor.test.publisher.TestPublisher) Arrays(java.util.Arrays) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Scheduler(reactor.core.scheduler.Scheduler) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) Subscriber(org.reactivestreams.Subscriber) Publisher(org.reactivestreams.Publisher) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Comparator(java.util.Comparator) Assert(org.junit.Assert) Collections(java.util.Collections) Scheduler(reactor.core.scheduler.Scheduler) Test(org.junit.Test)

Example 15 with Scheduler

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);
}
Also used : 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