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);
}
}
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();
}
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();
}
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();
}
}
}
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();
}
Aggregations