Search in sources :

Example 1 with Schedulers.parallel

use of reactor.core.scheduler.Schedulers.parallel in project reactor-core by reactor.

the class FluxPeekFuseableTest method should_reduce_to_10_events_conditional.

@Test
public void should_reduce_to_10_events_conditional() {
    for (int i = 0; i < 20; i++) {
        AtomicInteger count = new AtomicInteger();
        Flux.range(0, 10).flatMap(x -> Flux.range(0, 2).map(y -> blockingOp(x, y)).subscribeOn(Schedulers.parallel()).reduce((l, r) -> l + "_" + r).doOnSuccess(s -> {
            count.incrementAndGet();
        }).filter(v -> true)).blockLast();
        assertEquals(10, count.get());
    }
}
Also used : PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Thread.sleep(java.lang.Thread.sleep) MockUtils(reactor.test.MockUtils) Nullable(javax.annotation.Nullable) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Context(reactor.util.context.Context) Test(org.junit.Test) Schedulers.parallel(reactor.core.scheduler.Schedulers.parallel) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) List(java.util.List) Fuseable(reactor.core.Fuseable) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with Schedulers.parallel

use of reactor.core.scheduler.Schedulers.parallel in project reactor-core by reactor.

the class FluxPeekFuseableTest method should_reduce_to_10_events.

@Test
public void should_reduce_to_10_events() {
    for (int i = 0; i < 20; i++) {
        int n = i;
        List<Integer> rs = Collections.synchronizedList(new ArrayList<>());
        AtomicInteger count = new AtomicInteger();
        Flux.range(0, 10).flatMap(x -> Flux.range(0, 2).doOnNext(rs::add).map(y -> blockingOp(x, y)).subscribeOn(Schedulers.parallel()).reduce((l, r) -> l + "_" + r + " (" + x + ", it:" + n + ")")).doOnNext(s -> {
            count.incrementAndGet();
        }).blockLast();
        assertEquals(10, count.get());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Thread.sleep(java.lang.Thread.sleep) MockUtils(reactor.test.MockUtils) Nullable(javax.annotation.Nullable) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Context(reactor.util.context.Context) Test(org.junit.Test) Schedulers.parallel(reactor.core.scheduler.Schedulers.parallel) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) List(java.util.List) Fuseable(reactor.core.Fuseable) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) Schedulers(reactor.core.scheduler.Schedulers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Thread.sleep (java.lang.Thread.sleep)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Queue (java.util.Queue)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Consumer (java.util.function.Consumer)2 LongConsumer (java.util.function.LongConsumer)2 Nullable (javax.annotation.Nullable)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CoreMatchers (org.hamcrest.CoreMatchers)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 Mockito (org.mockito.Mockito)2 Subscription (org.reactivestreams.Subscription)2 CoreSubscriber (reactor.core.CoreSubscriber)2 Exceptions (reactor.core.Exceptions)2