use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class DefaultStepVerifierBuilderTests method suppliedVirtualTimeButNoSourceDoesntEnableScheduler.
@Test
public void suppliedVirtualTimeButNoSourceDoesntEnableScheduler() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
new DefaultStepVerifierBuilder<String>(StepVerifierOptions.create().initialRequest(Long.MAX_VALUE).virtualTimeSchedulerSupplier(() -> vts), // important to avoid triggering of vts capture-and-enable
null).expectNoEvent(Duration.ofSeconds(4)).expectComplete().toSubscriber();
try {
// also test the side effect case where VTS has been enabled and not reset
VirtualTimeScheduler current = VirtualTimeScheduler.get();
assertThat(current).isNotSameAs(vts);
} catch (IllegalStateException e) {
assertThat(e).hasMessageContaining("VirtualTimeScheduler");
}
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class StepVerifierTests method virtualTimeSchedulerUseExactlySupplied.
@Test
public void virtualTimeSchedulerUseExactlySupplied() {
VirtualTimeScheduler vts1 = VirtualTimeScheduler.create();
VirtualTimeScheduler vts2 = VirtualTimeScheduler.create();
VirtualTimeScheduler.getOrSet(vts1);
StepVerifier.withVirtualTime(Mono::empty, () -> vts2, Long.MAX_VALUE).then(() -> assertThat(VirtualTimeScheduler.get()).isSameAs(vts2)).verifyComplete();
assertThat(vts1.isDisposed()).isFalse();
assertThat(vts2.isDisposed()).isTrue();
assertThat(VirtualTimeScheduler.isFactoryEnabled()).isFalse();
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class StepVerifierTests method verifyVirtualTimeOnNextIntervalManual.
@Test(timeout = 3000)
public void verifyVirtualTimeOnNextIntervalManual() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
StepVerifier.withVirtualTime(() -> Flux.interval(Duration.ofMillis(1000), vts).map(d -> "t" + d)).then(() -> vts.advanceTimeBy(Duration.ofHours(1))).expectNextCount(3600).thenCancel().verify();
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class GuideTests method errorHandlingIntervalMillisRetried.
@Test
public void errorHandlingIntervalMillisRetried() throws InterruptedException {
VirtualTimeScheduler virtualTimeScheduler = VirtualTimeScheduler.create();
VirtualTimeScheduler.set(virtualTimeScheduler);
Flux<Tuple2<Long, String>> flux = Flux.interval(Duration.ofMillis(250)).map(input -> {
if (input < 3)
return "tick " + input;
throw new RuntimeException("boom");
}).elapsed().retry(1);
flux.subscribe(System.out::println, // <2>
System.err::println);
// Thread.sleep(2100); // <3>
virtualTimeScheduler.advanceTimeBy(Duration.ofHours(1));
StepVerifier.withVirtualTime(() -> flux, () -> virtualTimeScheduler, Long.MAX_VALUE).thenAwait(Duration.ofSeconds(3)).expectNextMatches(t -> t.getT2().equals("tick 0")).expectNextMatches(t -> t.getT2().equals("tick 1")).expectNextMatches(t -> t.getT2().equals("tick 2")).expectNextMatches(t -> t.getT2().equals("tick 0")).expectNextMatches(t -> t.getT2().equals("tick 1")).expectNextMatches(t -> t.getT2().equals("tick 2")).verifyErrorMessage("boom");
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class MonoTakeUntilOtherTest method apiTakeSchedulerShortcircuits.
@Test
public void apiTakeSchedulerShortcircuits() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
StepVerifier.create(Mono.delay(Duration.ofMillis(200)).take(Duration.ofSeconds(10), vts)).then(() -> vts.advanceTimeBy(Duration.ofSeconds(10))).verifyComplete();
}
Aggregations