use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class MonoDelayElementTest method cancelUpstreamOnceWhenRejected.
@Test
public void cancelUpstreamOnceWhenRejected() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
vts.dispose();
AtomicLong upstreamCancelCount = new AtomicLong();
Mono<String> source = Mono.just("foo").log().hide().doOnCancel(upstreamCancelCount::incrementAndGet);
try {
StepVerifier.withVirtualTime(() -> new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, vts).log(), () -> vts, Long.MAX_VALUE).expectSubscription().verifyComplete();
} catch (Throwable e) {
assertThat(e).hasMessageContaining("Scheduler unavailable");
} finally {
assertThat(upstreamCancelCount.get()).isEqualTo(1);
}
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class MonoDelayElementTest method cancelUpstreamOnceWhenCancelled.
@Test
public void cancelUpstreamOnceWhenCancelled() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
AtomicLong upstreamCancelCount = new AtomicLong();
Mono<String> source = Mono.just("foo").log().hide().doOnCancel(() -> upstreamCancelCount.incrementAndGet());
StepVerifier.withVirtualTime(() -> new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, vts), () -> vts, Long.MAX_VALUE).expectSubscription().expectNoEvent(Duration.ofSeconds(1)).thenCancel().verify();
vts.advanceTimeBy(Duration.ofHours(1));
assertThat(upstreamCancelCount.get()).isEqualTo(1);
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class GuideTests method errorHandlingIntervalMillisNotContinued.
@Test
public void errorHandlingIntervalMillisNotContinued() throws InterruptedException {
VirtualTimeScheduler virtualTimeScheduler = VirtualTimeScheduler.create();
VirtualTimeScheduler.set(virtualTimeScheduler);
Flux<String> flux = Flux.interval(Duration.ofMillis(250)).map(input -> {
if (input < 3)
return "tick " + input;
throw new RuntimeException("boom");
}).onErrorReturn("Uh oh");
flux.subscribe(System.out::println);
// Thread.sleep(2100); // <1>
virtualTimeScheduler.advanceTimeBy(Duration.ofHours(1));
StepVerifier.withVirtualTime(() -> flux, () -> virtualTimeScheduler, Long.MAX_VALUE).thenAwait(Duration.ofSeconds(3)).expectNext("tick 0").expectNext("tick 1").expectNext("tick 2").expectNext("Uh oh").verifyComplete();
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class StepVerifierTests method verifyVirtualTimeOnErrorAsync.
@Test
public void verifyVirtualTimeOnErrorAsync() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
StepVerifier.withVirtualTime(() -> Flux.just(123).subscribeOn(vts), () -> vts, 0).thenRequest(1).thenAwait().expectNext(123).expectComplete().verify();
}
Aggregations