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

The following examples show how to use reactor.test.publisher.TestPublisher#assertWasNotRequested() . 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: FluxTakeTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void takeZeroCancelsWhenNoRequest() {
	TestPublisher<Integer> ts = TestPublisher.create();
	StepVerifier.create(ts.flux()
	                      .take(0), 0)
	            .thenAwait()
	            .verifyComplete();

	ts.assertWasNotRequested();
	ts.assertWasCancelled();
}
 
Example 2
Source File: FluxTakeTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void takeZeroIgnoresRequestAndCancels() {
	TestPublisher<Integer> ts = TestPublisher.create();
	StepVerifier.create(ts.flux()
	                      .take(0), 3)
	            .thenAwait()
	            .verifyComplete();

	ts.assertWasNotRequested();
	ts.assertWasCancelled();
}
 
Example 3
Source File: FluxTakeTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void takeConditionalZeroCancelsWhenNoRequest() {
	TestPublisher<Integer> ts = TestPublisher.create();
	StepVerifier.create(ts.flux()
	                      .take(0)
	                      .filter(d -> true), 0)
	            .thenAwait()
	            .verifyComplete();

	ts.assertWasNotRequested();
	ts.assertWasCancelled();
}
 
Example 4
Source File: FluxTakeTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
public void takeConditionalZeroIgnoresRequestAndCancels() {
	TestPublisher<Integer> ts = TestPublisher.create();
	StepVerifier.create(ts.flux()
	                      .take(0)
	                      .filter(d -> true), 3)
	            .thenAwait()
	            .verifyComplete();

	ts.assertWasNotRequested();
	ts.assertWasCancelled();
}
 
Example 5
Source File: DefaultRSocketClientTests.java    From rsocket-java with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@MethodSource("interactions")
@SuppressWarnings({"unchecked", "rawtypes"})
public void shouldHaveNoLeaksOnPayloadInCaseOfRacingOfOnNextAndCancel(
    BiFunction<RSocketClient, Publisher<Payload>, Publisher<?>> request, FrameType requestType)
    throws Throwable {
  Assumptions.assumeThat(requestType).isNotEqualTo(FrameType.REQUEST_CHANNEL);

  for (int i = 0; i < 10000; i++) {
    ClientSocketRule rule = new ClientSocketRule();
    rule.apply(
            new Statement() {
              @Override
              public void evaluate() {}
            },
            null)
        .evaluate();
    Payload payload = ByteBufPayload.create("test", "testMetadata");
    TestPublisher<Payload> testPublisher =
        TestPublisher.createNoncompliant(TestPublisher.Violation.DEFER_CANCELLATION);
    AssertSubscriber assertSubscriber = AssertSubscriber.create(0);

    Publisher<?> publisher = request.apply(rule.client, testPublisher);
    publisher.subscribe(assertSubscriber);

    testPublisher.assertWasNotRequested();

    assertSubscriber.request(1);

    testPublisher.assertWasRequested();
    testPublisher.assertMaxRequested(1);
    testPublisher.assertMinRequested(1);

    RaceTestUtils.race(
        () -> {
          testPublisher.next(payload);
          rule.delayer.run();
        },
        assertSubscriber::cancel);

    Collection<ByteBuf> sent = rule.connection.getSent();
    if (sent.size() == 1) {
      Assertions.assertThat(sent)
          .allMatch(bb -> FrameHeaderCodec.frameType(bb).equals(requestType))
          .allMatch(ReferenceCounted::release);
    } else if (sent.size() == 2) {
      Assertions.assertThat(sent)
          .first()
          .matches(bb -> FrameHeaderCodec.frameType(bb).equals(requestType))
          .matches(ReferenceCounted::release);
      Assertions.assertThat(sent)
          .element(1)
          .matches(bb -> FrameHeaderCodec.frameType(bb).equals(FrameType.CANCEL))
          .matches(ReferenceCounted::release);
    } else {
      Assertions.assertThat(sent).isEmpty();
    }

    rule.allocator.assertHasNoLeaks();
  }
}