Java Code Examples for reactor.test.publisher.TestPublisher#assertNoRequestOverflow()

The following examples show how to use reactor.test.publisher.TestPublisher#assertNoRequestOverflow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FluxSwitchOnFirstTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotHangWhenOneElementUpstream() {
    TestPublisher<Long> publisher = TestPublisher.createCold();

    Flux<String> switchTransformed = publisher.flux()
                                              .switchOnFirst((first, innerFlux) ->
                                                  innerFlux.map(String::valueOf)
                                                           .subscriberContext(Context.of("a", "b"))
                                              )
                                              .subscriberContext(Context.of("a", "c"))
                                              .subscriberContext(Context.of("c", "d"));

    publisher.next(1L);
    publisher.complete();

    StepVerifier.create(switchTransformed, 0)
                .thenRequest(1)
                .expectNext("1")
                .expectComplete()
                .verify(Duration.ofSeconds(10));

    publisher.assertWasRequested();
    publisher.assertNoRequestOverflow();
}
 
Example 2
Source File: FluxSwitchOnFirstTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void backpressureTest() {
    TestPublisher<Long> publisher = TestPublisher.createCold();
    AtomicLong requested = new AtomicLong();

    Flux<String> switchTransformed = publisher.flux()
                                              .doOnRequest(requested::addAndGet)
                                              .switchOnFirst((first, innerFlux) -> innerFlux.map(String::valueOf));

    publisher.next(1L);

    StepVerifier.create(switchTransformed, 0)
                .thenRequest(1)
                .expectNext("1")
                .thenRequest(1)
                .then(() -> publisher.next(2L))
                .expectNext("2")
                .then(publisher::complete)
                .expectComplete()
                .verify(Duration.ofSeconds(10));

    publisher.assertWasRequested();
    publisher.assertNoRequestOverflow();

    Assertions.assertThat(requested.get()).isEqualTo(2L);
}
 
Example 3
Source File: FluxSwitchOnFirstTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldErrorOnOverflowTest() {
    TestPublisher<Long> publisher = TestPublisher.createCold();

    Flux<String> switchTransformed = publisher.flux()
                                              .switchOnFirst((first, innerFlux) -> innerFlux.map(String::valueOf));

    publisher.next(1L);

    StepVerifier.create(switchTransformed, 0)
                .thenRequest(1)
                .expectNext("1")
                .then(() -> publisher.next(2L))
                .expectErrorSatisfies(t -> Assertions
                    .assertThat(t)
                    .isInstanceOf(IllegalStateException.class)
                    .hasMessage("Can't deliver value due to lack of requests")
                )
                .verify(Duration.ofSeconds(10));

    publisher.assertWasRequested();
    publisher.assertNoRequestOverflow();
}
 
Example 4
Source File: FluxSwitchOnFirstTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotFailOnIncorrectPublisherBehavior() {
    TestPublisher<Long> publisher =
            TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);
    Flux<Long> switchTransformed = publisher.flux()
                                            .switchOnFirst((first, innerFlux) -> innerFlux.subscriberContext(Context.of("a", "b")));

    StepVerifier.create(new Flux<Long>() {
        @Override
        public void subscribe(CoreSubscriber<? super Long> actual) {
            switchTransformed.subscribe(actual);
            publisher.next(1L);
        }
    }, 0)
                .thenRequest(1)
                .expectNext(1L)
                .thenRequest(1)
                .then(() -> publisher.next(2L))
                .expectNext(2L)
                .then(() -> publisher.error(new RuntimeException()))
                .then(() -> publisher.error(new RuntimeException()))
                .then(() -> publisher.error(new RuntimeException()))
                .then(() -> publisher.error(new RuntimeException()))
                .expectError()
                .verifyThenAssertThat(Duration.ofSeconds(5))
                .hasDroppedErrors(3)
                .tookLessThan(Duration.ofSeconds(10));

    publisher.assertWasRequested();
    publisher.assertNoRequestOverflow();
}
 
Example 5
Source File: FluxSwitchOnFirstTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
// Since context is immutable, with switchOnFirst it should not be mutable as well. Upstream should observe downstream
// Inner should be able to access downstreamContext but should not modify upstream context after the first element
public void shouldNotBeAbleToAccessUpstreamContext() {
    TestPublisher<Long> publisher = TestPublisher.createCold();

    Flux<String> switchTransformed = publisher.flux()
                                              .switchOnFirst(
                                                  (first, innerFlux) -> innerFlux.map(String::valueOf)
                                                                                 .subscriberContext(Context.of("a", "b"))
                                              )
                                              .subscriberContext(Context.of("a", "c"))
                                              .subscriberContext(Context.of("c", "d"));

    publisher.next(1L);

    StepVerifier.create(switchTransformed, 0)
                .thenRequest(1)
                .expectNext("1")
                .thenRequest(1)
                .then(() -> publisher.next(2L))
                .expectNext("2")
                .expectAccessibleContext()
                .contains("a", "c")
                .contains("c", "d")
                .then()
                .then(publisher::complete)
                .expectComplete()
                .verify(Duration.ofSeconds(10));

    publisher.assertWasRequested();
    publisher.assertNoRequestOverflow();
}