use of reactor.test.publisher.TestPublisher in project reactor-core by reactor.
the class StepVerifierTests method thenCancel_cancelsAfterFirst2.
@Test
public void thenCancel_cancelsAfterFirst2() {
TestPublisher<Long> publisher = TestPublisher.create();
AtomicBoolean downStreamCancelled = new AtomicBoolean();
AtomicBoolean asserted = new AtomicBoolean();
Flux<Long> source = publisher.flux().doOnCancel(() -> downStreamCancelled.set(true));
Duration took = StepVerifier.create(source).then(() -> Schedulers.elastic().schedule(() -> publisher.next(0L))).assertNext(next -> {
asserted.set(true);
assertThat(next).isEqualTo(0L);
}).then(() -> Schedulers.elastic().schedule(() -> publisher.next(1L))).thenCancel().verify(Duration.ofSeconds(5));
publisher.assertCancelled();
assertThat(asserted.get()).as("expectation processed").isTrue();
assertThat(downStreamCancelled.get()).as("is cancelled by awaitThenCancel").isTrue();
}
use of reactor.test.publisher.TestPublisher in project reactor-core by reactor.
the class StepVerifierTests method thenCancel_cancelsAfterFirst.
@Test
public void thenCancel_cancelsAfterFirst() {
TestPublisher<Long> publisher = TestPublisher.create();
AtomicBoolean downStreamCancelled = new AtomicBoolean();
AtomicBoolean asserted = new AtomicBoolean();
Flux<Long> source = publisher.flux().onBackpressureBuffer().doOnCancel(() -> downStreamCancelled.set(true)).log();
Duration took = StepVerifier.create(source, 1).then(() -> Schedulers.elastic().schedule(() -> publisher.next(0L))).assertNext(next -> {
LockSupport.parkNanos(Duration.ofMillis(500).toNanos());
asserted.set(true);
assertThat(next).isEqualTo(0L);
}).then(() -> Schedulers.elastic().schedule(() -> publisher.next(1L))).then(() -> Schedulers.elastic().schedule(() -> publisher.next(2L), 50, TimeUnit.MILLISECONDS)).expectNoEvent(Duration.ofMillis(100)).thenRequest(1).thenRequest(1).assertNext(next -> {
LockSupport.parkNanos(Duration.ofMillis(500).toNanos());
assertThat(next).isEqualTo(1L);
}).thenAwait(Duration.ofSeconds(2)).thenCancel().verify(Duration.ofSeconds(5));
publisher.assertCancelled();
assertThat(asserted.get()).as("expectation processed").isTrue();
assertThat(downStreamCancelled.get()).as("is cancelled by awaitThenCancel").isTrue();
assertThat(took.toMillis()).as("blocked on first assertNext").isGreaterThanOrEqualTo(1000L);
}
Aggregations