Search in sources :

Example 1 with DROP

use of reactor.core.publisher.FluxSink.OverflowStrategy.DROP in project reactor-core by reactor.

the class FluxSubscribeOnTest method forceScheduledRequests.

@Test
public void forceScheduledRequests() {
    Flux<Integer> test = Flux.<Integer>create(sink -> {
        for (int i = 1; i < 1001; i++) {
            sink.next(i);
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        sink.complete();
    }, DROP).map(Function.identity()).subscribeOn(Schedulers.single(), true).publishOn(Schedulers.elastic());
    AtomicInteger count = new AtomicInteger();
    StepVerifier.create(test).thenConsumeWhile(t -> count.incrementAndGet() != -1).expectComplete().verify(Duration.ofSeconds(5));
    assertThat(count.get()).isEqualTo(Queues.SMALL_BUFFER_SIZE);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Publisher(org.reactivestreams.Publisher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) Queues(reactor.util.concurrent.Queues) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) CoreSubscriber(reactor.core.CoreSubscriber) DROP(reactor.core.publisher.FluxSink.OverflowStrategy.DROP) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with DROP

use of reactor.core.publisher.FluxSink.OverflowStrategy.DROP in project reactor-core by reactor.

the class FluxSubscribeOnTest method forceNoScheduledRequests.

@Test
public void forceNoScheduledRequests() {
    Flux<Integer> test = Flux.<Integer>create(sink -> {
        for (int i = 1; i < 1001; i++) {
            sink.next(i);
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        sink.complete();
    }, DROP).map(Function.identity()).subscribeOn(Schedulers.single(), false).publishOn(Schedulers.elastic());
    AtomicInteger count = new AtomicInteger();
    StepVerifier.create(test).thenConsumeWhile(t -> count.incrementAndGet() != -1).expectComplete().verify(Duration.ofSeconds(5));
    assertThat(count.get()).isGreaterThan(Queues.SMALL_BUFFER_SIZE);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Publisher(org.reactivestreams.Publisher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) Queues(reactor.util.concurrent.Queues) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) CoreSubscriber(reactor.core.CoreSubscriber) DROP(reactor.core.publisher.FluxSink.OverflowStrategy.DROP) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Duration (java.time.Duration)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Function (java.util.function.Function)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 Publisher (org.reactivestreams.Publisher)2 Subscription (org.reactivestreams.Subscription)2 CoreSubscriber (reactor.core.CoreSubscriber)2 Scannable (reactor.core.Scannable)2 DROP (reactor.core.publisher.FluxSink.OverflowStrategy.DROP)2 Scheduler (reactor.core.scheduler.Scheduler)2 Schedulers (reactor.core.scheduler.Schedulers)2 StepVerifier (reactor.test.StepVerifier)2 AssertSubscriber (reactor.test.subscriber.AssertSubscriber)2 Queues (reactor.util.concurrent.Queues)2