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

The following examples show how to use reactor.test.publisher.TestPublisher#assertSubscribers() . 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: RSocketTest.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
void nextFromRequesterPublisher(
    TestPublisher<Payload> requesterPublisher, AssertSubscriber<Payload> responderSubscriber) {
  // ensures that outerUpstream and innerSubscriber is not terminated so the requestChannel
  requesterPublisher.assertSubscribers(1);
  responderSubscriber.assertNotTerminated();

  responderSubscriber.request(6);
  requesterPublisher.next(
      DefaultPayload.create("d1", "m1"),
      DefaultPayload.create("d2"),
      DefaultPayload.create("d3", "m3"),
      DefaultPayload.create("d4"),
      DefaultPayload.create("d5", "m5"));

  List<Payload> innerPayloads = responderSubscriber.awaitAndAssertNextValueCount(6).values();
  Assertions.assertThat(innerPayloads.stream().map(Payload::getDataUtf8))
      .containsExactly("initialData", "d1", "d2", "d3", "d4", "d5");
  Assertions.assertThat(innerPayloads.stream().map(Payload::hasMetadata))
      .containsExactly(true, true, false, true, false, true);
  Assertions.assertThat(innerPayloads.stream().map(Payload::getMetadataUtf8))
      .containsExactly("initialMetadata", "m1", "", "m3", "", "m5");
}
 
Example 2
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
void nextFromResponderPublisher(
    TestPublisher<Payload> responderPublisher, AssertSubscriber<Payload> requesterSubscriber) {
  // ensures that downstream is not terminated so the requestChannel state is half-closed
  responderPublisher.assertSubscribers(1);
  requesterSubscriber.assertNotTerminated();

  // ensures responderPublisher can send messages and outerSubscriber can receive them
  requesterSubscriber.request(5);
  responderPublisher.next(
      DefaultPayload.create("rd1", "rm1"),
      DefaultPayload.create("rd2"),
      DefaultPayload.create("rd3", "rm3"),
      DefaultPayload.create("rd4"),
      DefaultPayload.create("rd5", "rm5"));

  List<Payload> outerPayloads = requesterSubscriber.awaitAndAssertNextValueCount(5).values();
  Assertions.assertThat(outerPayloads.stream().map(Payload::getDataUtf8))
      .containsExactly("rd1", "rd2", "rd3", "rd4", "rd5");
  Assertions.assertThat(outerPayloads.stream().map(Payload::hasMetadata))
      .containsExactly(true, false, true, false, true);
  Assertions.assertThat(outerPayloads.stream().map(Payload::getMetadataUtf8))
      .containsExactly("rm1", "", "rm3", "", "rm5");
}
 
Example 3
Source File: ReconnectMonoTests.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotExpiredIfNotCompleted() {
  final TestPublisher<String> publisher =
      TestPublisher.createNoncompliant(TestPublisher.Violation.REQUEST_OVERFLOW);

  final ReconnectMono<String> reconnectMono =
      publisher.mono().as(source -> new ReconnectMono<>(source, onExpire(), onValue()));

  MonoProcessor<String> processor = MonoProcessor.create();

  reconnectMono.subscribe(processor);

  Assertions.assertThat(expired).isEmpty();
  Assertions.assertThat(received).isEmpty();
  Assertions.assertThat(processor.isTerminated()).isFalse();

  publisher.next("test");

  Assertions.assertThat(expired).isEmpty();
  Assertions.assertThat(received).isEmpty();
  Assertions.assertThat(processor.isTerminated()).isFalse();

  reconnectMono.invalidate();

  Assertions.assertThat(expired).isEmpty();
  Assertions.assertThat(received).isEmpty();
  Assertions.assertThat(processor.isTerminated()).isFalse();
  publisher.assertSubscribers(1);
  Assertions.assertThat(publisher.subscribeCount()).isEqualTo(1);

  publisher.complete();

  Assertions.assertThat(expired).isEmpty();
  Assertions.assertThat(received).hasSize(1);
  Assertions.assertThat(processor.isTerminated()).isTrue();

  publisher.assertSubscribers(0);
  Assertions.assertThat(publisher.subscribeCount()).isEqualTo(1);
}