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

The following examples show how to use reactor.test.publisher.TestPublisher#assertNoSubscribers() . 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: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void startError() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.create();
	final TestPublisher<Integer> end = TestPublisher.create();

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.error(new IllegalStateException("boom")))
	            .expectErrorMessage("boom")
	            .verify();

	source.assertNoSubscribers();
	start.assertNoSubscribers();
	end.assertNoSubscribers();
}
 
Example 2
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void startDoneThenError() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);
	final TestPublisher<Integer> end = TestPublisher.create();

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.error(new IllegalStateException("boom"))
	                             .error(new IllegalStateException("boom2")))
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasDroppedErrorWithMessage("boom2");

	source.assertNoSubscribers();
	//start doesn't cleanup and as such still has a subscriber
	end.assertNoSubscribers();
}
 
Example 3
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void startDoneThenComplete() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);
	final TestPublisher<Integer> end = TestPublisher.create();

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.error(new IllegalStateException("boom"))
	                             .complete())
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasNotDroppedErrors();

	source.assertNoSubscribers();
	//start doesn't cleanup and as such still has a subscriber
	end.assertNoSubscribers();
}
 
Example 4
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void startDoneThenNext() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);
	final TestPublisher<Integer> end = TestPublisher.create();

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.error(new IllegalStateException("boom"))
	                             .next(1))
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasNotDroppedErrors()
	            .hasNotDroppedElements();

	source.assertNoSubscribers();
	//start doesn't cleanup and as such still has a subscriber
	end.assertNoSubscribers();
}
 
Example 5
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void endError() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.create();
	TestPublisher<Integer> end = TestPublisher.create();

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.next(1))
	            .then(() -> end.error(new IllegalStateException("boom")))
	            .expectErrorMessage("boom")
	            .verify();

	source.assertNoSubscribers();
	start.assertNoSubscribers();
	end.assertNoSubscribers();
}
 
Example 6
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void endDoneThenError() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.create();
	TestPublisher<Integer> end = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.next(1))
	            .then(() -> end.error(new IllegalStateException("boom"))
	                           .error(new IllegalStateException("boom2")))
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasDroppedErrorWithMessage("boom2");

	source.assertNoSubscribers();
	start.assertNoSubscribers();
	//end doesn't cleanup and as such still has a subscriber
}
 
Example 7
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void endDoneThenComplete() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.create();
	TestPublisher<Integer> end = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.next(1))
	            .then(() -> end.error(new IllegalStateException("boom"))
	                           .complete())
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasNotDroppedErrors();

	source.assertNoSubscribers();
	start.assertNoSubscribers();
	//end doesn't cleanup and as such still has a subscriber
}
 
Example 8
Source File: FluxWindowWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void endDoneThenNext() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> start = TestPublisher.create();
	TestPublisher<Integer> end = TestPublisher.createNoncompliant(TestPublisher.Violation.CLEANUP_ON_TERMINATE);

	StepVerifier.create(source.flux()
	                          .windowWhen(start, v -> end)
	                          .flatMap(Flux.identityFunction())
	)
	            .then(() -> start.next(1))
	            .then(() -> end.error(new IllegalStateException("boom"))
	                           .next(1))
	            .expectErrorMessage("boom")
	            .verifyThenAssertThat()
	            .hasNotDroppedErrors()
	            .hasNotDroppedElements();

	source.assertNoSubscribers();
	start.assertNoSubscribers();
	//end doesn't cleanup and as such still has a subscriber
}
 
Example 9
Source File: FluxBufferWhenTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void openCloseDisposedOnComplete() {
	TestPublisher<Integer> source = TestPublisher.create();
	TestPublisher<Integer> open = TestPublisher.create();
	TestPublisher<Integer> close = TestPublisher.create();

	StepVerifier.create(source
			.flux()
			.bufferWhen(open, o -> close))
	            .then(() -> {
		            source.assertSubscribers();
		            open.assertSubscribers();
		            close.assertNoSubscribers();
		            open.next(1);
	            })
	            .then(() -> {
					open.assertSubscribers();
					close.assertSubscribers();
					source.complete();
	            })
	            .expectNextMatches(List::isEmpty)
	            .verifyComplete();

	open.assertNoSubscribers();
	close.assertNoSubscribers();
}
 
Example 10
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
void errorFromResponderPublisher(
    TestPublisher<Payload> requesterPublisher,
    AssertSubscriber<Payload> requesterSubscriber,
    TestPublisher<Payload> responderPublisher,
    AssertSubscriber<Payload> responderSubscriber) {
  // ensures that after sending cancel the whole requestChannel is terminated
  responderPublisher.error(EXCEPTION);
  // error should be propagated
  responderSubscriber.assertTerminated().assertError(CancellationException.class);
  requesterSubscriber
      .assertTerminated()
      .assertError(CustomRSocketException.class)
      .assertErrorMessage("test");
  // ensures that cancellation is propagated to the actual upstream
  requesterPublisher.assertWasCancelled();
  requesterPublisher.assertNoSubscribers();
}
 
Example 11
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
void errorFromRequesterPublisher(
    TestPublisher<Payload> requesterPublisher,
    AssertSubscriber<Payload> requesterSubscriber,
    TestPublisher<Payload> responderPublisher,
    AssertSubscriber<Payload> responderSubscriber) {
  // ensures that after sending cancel the whole requestChannel is terminated
  requesterPublisher.error(EXCEPTION);
  // error should be propagated
  responderSubscriber
      .assertTerminated()
      .assertError(CustomRSocketException.class)
      .assertErrorMessage("test");
  requesterSubscriber
      .assertTerminated()
      .assertError(CustomRSocketException.class)
      .assertErrorMessage("test");

  // ensures that cancellation is propagated to the actual upstream
  responderPublisher.assertWasCancelled();
  responderPublisher.assertNoSubscribers();
}
 
Example 12
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
void completeFromRequesterPublisher(
    TestPublisher<Payload> requesterPublisher, AssertSubscriber<Payload> responderSubscriber) {
  // ensures that after sending complete upstream part is closed
  requesterPublisher.complete();
  responderSubscriber.assertTerminated();
  requesterPublisher.assertNoSubscribers();
}
 
Example 13
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
void cancelFromResponderSubscriber(
    TestPublisher<Payload> requesterPublisher, AssertSubscriber<Payload> responderSubscriber) {
  // ensures that after sending complete upstream part is closed
  responderSubscriber.cancel();
  requesterPublisher.assertWasCancelled();
  requesterPublisher.assertNoSubscribers();
}
 
Example 14
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
void completeFromResponderPublisher(
    TestPublisher<Payload> responderPublisher, AssertSubscriber<Payload> requesterSubscriber) {
  // ensures that after sending complete inner upstream is closed
  responderPublisher.complete();
  requesterSubscriber.assertTerminated();
  responderPublisher.assertNoSubscribers();
}
 
Example 15
Source File: RSocketTest.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
void cancelFromRequesterSubscriber(
    TestPublisher<Payload> requesterPublisher,
    AssertSubscriber<Payload> requesterSubscriber,
    TestPublisher<Payload> responderPublisher,
    AssertSubscriber<Payload> responderSubscriber) {
  // ensures that after sending cancel the whole requestChannel is terminated
  requesterSubscriber.cancel();
  // error should be propagated
  responderSubscriber.assertTerminated();
  responderPublisher.assertWasCancelled();
  responderPublisher.assertNoSubscribers();
  // ensures that cancellation is propagated to the actual upstream
  requesterPublisher.assertWasCancelled();
  requesterPublisher.assertNoSubscribers();
}