use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class FluxRefCountGraceTest method shouldNotRetainSubscriptionToSourceWhenComplete.
@Test
public void shouldNotRetainSubscriptionToSourceWhenComplete() throws Exception {
VirtualTimeScheduler scheduler = VirtualTimeScheduler.create();
Duration gracePeriod = Duration.ofMillis(10);
Flux<String> f = Flux.just("hello world").replay(1).refCount(1, gracePeriod, scheduler);
AssertSubscriber<String> s = AssertSubscriber.create();
f.subscribe(s);
scheduler.advanceTimeBy(gracePeriod);
StepVerifier.create(f.next()).expectNext("hello world").verifyComplete();
scheduler.advanceTimeBy(gracePeriod);
s.assertValueCount(1).assertNoError().assertComplete();
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class FluxCacheTest method cacheFluxHistoryTTL.
@Test
public void cacheFluxHistoryTTL() {
try {
// delayElements now uses parallel() so VTS must be enabled everywhere
VirtualTimeScheduler vts = VirtualTimeScheduler.getOrSet();
Flux<Tuple2<Long, Integer>> source = Flux.just(1, 2, 3).delayElements(Duration.ofMillis(1000)).cache(2, Duration.ofMillis(2000)).elapsed();
StepVerifier.create(source).then(() -> vts.advanceTimeBy(Duration.ofSeconds(3))).expectNextMatches(t -> t.getT1() == 1000 && t.getT2() == 1).expectNextMatches(t -> t.getT1() == 1000 && t.getT2() == 2).expectNextMatches(t -> t.getT1() == 1000 && t.getT2() == 3).verifyComplete();
StepVerifier.create(source).then(() -> vts.advanceTimeBy(Duration.ofSeconds(3))).expectNextMatches(t -> t.getT1() == 0 && t.getT2() == 2).expectNextMatches(t -> t.getT1() == 0 && t.getT2() == 3).verifyComplete();
} finally {
VirtualTimeScheduler.reset();
}
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class MonoDelayElementTest method cancelBeforeNext.
@Test
public void cancelBeforeNext() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
AtomicBoolean emitted = new AtomicBoolean();
AtomicBoolean cancelled = new AtomicBoolean();
Mono<Long> source = Mono.delay(Duration.ofMillis(1000), vts);
StepVerifier.withVirtualTime(() -> new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, vts).doOnCancel(() -> cancelled.set(true)).doOnNext(n -> emitted.set(true)), () -> vts, Long.MAX_VALUE).expectSubscription().expectNoEvent(Duration.ofMillis(500)).thenCancel().verify();
vts.advanceTimeBy(Duration.ofHours(1));
assertThat(emitted.get()).isFalse();
assertThat(cancelled.get()).isTrue();
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class MonoDelayElementTest method monoApiTestMillisAndTimer.
@Test
public void monoApiTestMillisAndTimer() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
StepVerifier.withVirtualTime(() -> Mono.just("foo").delayElement(Duration.ofMillis(5000L), vts), () -> vts, Long.MAX_VALUE).expectSubscription().expectNoEvent(Duration.ofSeconds(5)).expectNext("foo").verifyComplete();
}
use of reactor.test.scheduler.VirtualTimeScheduler in project reactor-core by reactor.
the class MonoDelayElementTest method cancelDuringDelay.
@Test
public void cancelDuringDelay() {
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
AtomicBoolean emitted = new AtomicBoolean();
AtomicBoolean cancelled = new AtomicBoolean();
Mono<String> source = Mono.just("foo").log().hide();
StepVerifier.withVirtualTime(() -> new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, vts).doOnCancel(() -> cancelled.set(true)).log().doOnNext(n -> emitted.set(true)), () -> vts, Long.MAX_VALUE).expectSubscription().expectNoEvent(Duration.ofSeconds(1)).thenCancel().verify();
vts.advanceTimeBy(Duration.ofHours(1));
assertThat(emitted.get()).isFalse();
assertThat(cancelled.get()).isTrue();
}
Aggregations