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

The following examples show how to use reactor.test.publisher.TestPublisher#subscribe() . 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: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleOnSubscribe() {
    TestPublisher<String> publisher = TestPublisher.create();

    publisher.subscribe(subscriber);

    publisher.assertMinRequested(1);
    verify(mockWriteStream).drainHandler(any(Handler.class));
}
 
Example 2
Source File: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWriteAndRequestOnNext() {
    TestPublisher<String> publisher = TestPublisher.create();
    publisher.subscribe(subscriber);

    publisher.next("test");

    verify(mockWriteStream).write("test");
    publisher.assertMinRequested(1);
}
 
Example 3
Source File: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotRequestIfFull() {
    given(mockWriteStream.writeQueueFull()).willReturn(true);

    TestPublisher<String> publisher = TestPublisher.create();
    publisher.subscribe(subscriber);

    publisher.assertMinRequested(0);
}
 
Example 4
Source File: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleComplete() {
    TestPublisher<String> publisher = TestPublisher.create();
    publisher.subscribe(subscriber);

    publisher.complete();

    verify(mockMonoSink).success();
}
 
Example 5
Source File: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleCancel() {
    TestPublisher<String> publisher = TestPublisher.create();
    publisher.subscribe(subscriber);

    subscriber.cancel();

    verify(mockMonoSink).success();
}
 
Example 6
Source File: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleError() {
    TestPublisher<String> publisher = TestPublisher.create();
    publisher.subscribe(subscriber);

    RuntimeException exception = new RuntimeException("test");
    publisher.error(exception);

    verify(mockMonoSink).error(exception);
}
 
Example 7
Source File: WriteStreamSubscriberTest.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyCompleteFlow() {
    TestWriteStream<String> writeStream = new TestWriteStream<>();
    TestPublisher<String> publisher = TestPublisher.create();

    Subscriber<String> subscriber = new WriteStreamSubscriber.Builder<WriteStream<String>, String>()
        .writeStream(writeStream)
        .nextHandler(WriteStream::write)
        .endHook(mockMonoSink)
        .build();

    writeStream.setWriteQueueMaxSize(2);

    publisher.subscribe(subscriber);
    publisher.assertMinRequested(1);

    publisher.next("first");
    publisher.assertMinRequested(1);

    publisher.next("second");
    publisher.assertMinRequested(0);
    assertThat(writeStream.getReceived()).containsOnly("first", "second");

    writeStream.clearReceived();
    publisher.assertMinRequested(1);

    publisher.next("third");
    assertThat(writeStream.getReceived()).containsOnly("third");

    publisher.complete();
    verify(mockMonoSink).success();
}
 
Example 8
Source File: UnicastProcessorTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureNoLeaksIfRacingDisposeAndOnNext() {
	Hooks.onNextDropped(MemoryUtils.Tracked::safeRelease);
	try {
		MemoryUtils.OffHeapDetector tracker = new MemoryUtils.OffHeapDetector();
		for (int i = 0; i < 10000; i++) {
			tracker.reset();
			TestPublisher<MemoryUtils.Tracked> testPublisher = TestPublisher.createNoncompliant(TestPublisher.Violation.DEFER_CANCELLATION,
					TestPublisher.Violation.REQUEST_OVERFLOW);
			UnicastProcessor<MemoryUtils.Tracked> unicastProcessor = UnicastProcessor.create();

			testPublisher.subscribe(unicastProcessor);

			AssertSubscriber<MemoryUtils.Tracked> assertSubscriber =
					new AssertSubscriber<>(Operators.enableOnDiscard(null, MemoryUtils.Tracked::safeRelease));

			unicastProcessor.subscribe(assertSubscriber);

			testPublisher.next(tracker.track(1));
			testPublisher.next(tracker.track(2));

			MemoryUtils.Tracked value3 = tracker.track(3);
			MemoryUtils.Tracked value4 = tracker.track(4);
			MemoryUtils.Tracked value5 = tracker.track(5);

			RaceTestUtils.race(unicastProcessor::dispose, () -> {
				testPublisher.next(value3);
				testPublisher.next(value4);
				testPublisher.next(value5);
			});

			assertSubscriber.assertTerminated()
			                .assertError(CancellationException.class)
			                .assertErrorMessage("Disposed");

			List<MemoryUtils.Tracked> values = assertSubscriber.values();
			values.forEach(MemoryUtils.Tracked::release);

			tracker.assertNoLeaks();
		}
	} finally {
		Hooks.resetOnNextDropped();
	}
}