Search in sources :

Example 26 with Scheduler

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

the class MonoDelayElementTest method onNextOnDisposedSchedulerThrows.

@Test
public void onNextOnDisposedSchedulerThrows() {
    Scheduler scheduler = Schedulers.newSingle("onNextOnDisposedSchedulerThrows");
    scheduler.dispose();
    Mono<String> source = Mono.just("foo").hide();
    try {
        StepVerifier.create(new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, scheduler)).expectSubscription().verifyComplete();
        fail("expected exception here");
    } catch (Throwable e) {
        Throwable t = Exceptions.unwrap(e);
        assertThat(t).isEqualTo(e).isInstanceOf(RejectedExecutionException.class).hasMessage("Scheduler unavailable");
        assertThat(e).satisfies(Exceptions::isBubbling);
    }
}
Also used : VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) Scheduler(reactor.core.scheduler.Scheduler) Test(org.junit.Test)

Example 27 with Scheduler

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

the class WorkQueueProcessorTest method testBufferSize1Created.

// see https://github.com/reactor/reactor-core/issues/445
@Test(timeout = 5_000)
public void testBufferSize1Created() throws Exception {
    WorkQueueProcessor<String> broadcast = WorkQueueProcessor.<String>builder().share(true).name("share-name").bufferSize(1).autoCancel(true).build();
    int simultaneousSubscribers = 3000;
    CountDownLatch latch = new CountDownLatch(simultaneousSubscribers);
    Scheduler scheduler = Schedulers.single();
    FluxSink<String> sink = broadcast.sink();
    Flux<String> flux = broadcast.filter(Objects::nonNull).publishOn(scheduler).cache(1);
    for (int i = 0; i < simultaneousSubscribers; i++) {
        flux.subscribe(s -> latch.countDown());
    }
    sink.next("data");
    Assertions.assertThat(latch.await(4, TimeUnit.SECONDS)).overridingErrorMessage("Data not received").isTrue();
}
Also used : Scheduler(reactor.core.scheduler.Scheduler) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 28 with Scheduler

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

the class WorkQueueProcessorTest method testBufferSize1Shared.

// see https://github.com/reactor/reactor-core/issues/445
@Test(timeout = 5_000)
public void testBufferSize1Shared() throws Exception {
    WorkQueueProcessor<String> broadcast = WorkQueueProcessor.<String>builder().share(true).name("share-name").bufferSize(1).autoCancel(true).build();
    int simultaneousSubscribers = 3000;
    CountDownLatch latch = new CountDownLatch(simultaneousSubscribers);
    Scheduler scheduler = Schedulers.single();
    FluxSink<String> sink = broadcast.sink();
    Flux<String> flux = broadcast.filter(Objects::nonNull).publishOn(scheduler).cache(1);
    for (int i = 0; i < simultaneousSubscribers; i++) {
        flux.subscribe(s -> latch.countDown());
    }
    sink.next("data");
    Assertions.assertThat(latch.await(4, TimeUnit.SECONDS)).overridingErrorMessage("Data not received").isTrue();
}
Also used : Scheduler(reactor.core.scheduler.Scheduler) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 29 with Scheduler

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

the class FluxPublishOnLoop method crossRangePerfDefaultLoop2.

@Test
public void crossRangePerfDefaultLoop2() {
    Scheduler scheduler = Schedulers.fromExecutorService(FluxPublishOnTest.exec);
    int count = 1000;
    for (int j = 1; j < 256; j *= 2) {
        Flux<Integer> source = Flux.range(1, count).flatMap(v -> Flux.range(v, 2), 128, j).publishOn(scheduler);
        StepVerifier.Step<Integer> v = StepVerifier.create(source).expectNextCount(count * 2);
        for (int i = 0; i < 10000; i++) {
            v.verifyComplete();
        }
    }
}
Also used : Flux(reactor.core.publisher.Flux) AfterClass(org.junit.AfterClass) StepVerifier(reactor.test.StepVerifier) BeforeClass(org.junit.BeforeClass) Schedulers(reactor.core.scheduler.Schedulers) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Executors(java.util.concurrent.Executors) FluxPublishOnTest(reactor.core.publisher.FluxPublishOnTest) Scheduler(reactor.core.scheduler.Scheduler) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test) FluxPublishOnTest(reactor.core.publisher.FluxPublishOnTest)

Example 30 with Scheduler

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

the class CombinationTests method sampleZipTest3.

@Test
public void sampleZipTest3() throws Exception {
    int elements = 1;
    CountDownLatch latch = new CountDownLatch(elements + 1);
    EmitterProcessor<SensorData> sensorDataProcessor = EmitterProcessor.create();
    Scheduler scheduler = Schedulers.single();
    sensorDataProcessor.publishOn(scheduler).subscribe(d -> latch.countDown(), null, latch::countDown);
    Flux.zip(Flux.just(new SensorData(2L, 12.0f)), Flux.just(new SensorData(1L, 14.0f)), this::computeMin).log("zip3").subscribe(sensorDataProcessor);
    awaitLatch(null, latch);
    scheduler.dispose();
}
Also used : Scheduler(reactor.core.scheduler.Scheduler) CountDownLatch(java.util.concurrent.CountDownLatch) 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