Java Code Examples for reactor.test.publisher.TestPublisher#flux()
The following examples show how to use
reactor.test.publisher.TestPublisher#flux() .
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: AbstractEventHandlerTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_resubscribe_after_error() { TestPublisher<InstanceEvent> testPublisher = TestPublisher.create(); TestEventHandler eventHandler = new TestEventHandler(testPublisher.flux()); eventHandler.start(); StepVerifier.create(eventHandler.getFlux()) .expectSubscription() .then(() -> testPublisher.next(event)) .expectNext(event) .then(() -> testPublisher.next(errorEvent)) .expectNoEvent(Duration.ofMillis(100L)) .then(() -> testPublisher.next(event)) .expectNext(event) .thenCancel() .verify(Duration.ofSeconds(5)); }
Example 2
Source File: AbstractEventHandlerTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_filter() { TestPublisher<InstanceEvent> testPublisher = TestPublisher.create(); TestEventHandler eventHandler = new TestEventHandler(testPublisher.flux()); eventHandler.start(); StepVerifier.create(eventHandler.getFlux()) .expectSubscription() .then(() -> testPublisher.next(event)) .expectNext(event) .then(() -> testPublisher.next(ignoredEvent)) .expectNoEvent(Duration.ofMillis(100L)) .thenCancel() .verify(Duration.ofSeconds(5)); }
Example 3
Source File: ReactorDemoTest.java From reactive-streams-in-java with Apache License 2.0 | 5 votes |
@Test public void test_TestPublisher() { TestPublisher<Object> publisher = TestPublisher.create(); //1 Flux<Object> stringFlux = publisher.flux(); //2 List list = new ArrayList(); //3 stringFlux.subscribe(next -> list.add(next), ex -> ex.printStackTrace()); //4 publisher.emit("foo", "bar"); //5 assertEquals(2, list.size()); //6 assertEquals("foo", list.get(0)); assertEquals("bar", list.get(1)); }
Example 4
Source File: AbstractEventHandlerTest.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Test public void should_resubscribe_after_error() { TestPublisher<InstanceEvent> testPublisher = TestPublisher.create(); TestEventHandler eventHandler = new TestEventHandler(testPublisher.flux()); eventHandler.start(); StepVerifier.create(eventHandler.getFlux()).expectSubscription() .then(() -> testPublisher.next(firstEvent, errorEvent, secondEvent)).expectNext(firstEvent, secondEvent) .thenCancel().verify(Duration.ofSeconds(1)); }
Example 5
Source File: AbstractEventHandlerTest.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Test public void should_filter() { TestPublisher<InstanceEvent> testPublisher = TestPublisher.create(); TestEventHandler eventHandler = new TestEventHandler(testPublisher.flux()); eventHandler.start(); StepVerifier.create(eventHandler.getFlux()).expectSubscription() .then(() -> testPublisher.next(firstEvent, ignoredEvent, secondEvent)) .expectNext(firstEvent, secondEvent).thenCancel().verify(Duration.ofSeconds(1)); }
Example 6
Source File: TestingTestPublisherUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void testPublisherInAction() { final TestPublisher<String> testPublisher = TestPublisher.create(); UppercaseConverter uppercaseConverter = new UppercaseConverter(testPublisher.flux()); StepVerifier.create(uppercaseConverter.getUpperCase()) .then(() -> testPublisher.emit("aA", "bb", "ccc")) .expectNext("AA", "BB", "CCC") .verifyComplete(); }
Example 7
Source File: InfoUpdateTriggerTest.java From Moss with Apache License 2.0 | 4 votes |
@Test public void should_update_on_event() throws InterruptedException { //given InfoUpdater updater = mock(InfoUpdater.class); when(updater.updateInfo(any(InstanceId.class))).thenReturn(Mono.empty()); TestPublisher<InstanceEvent> events = TestPublisher.create(); InfoUpdateTrigger trigger = new InfoUpdateTrigger(updater, events.flux()); trigger.start(); Thread.sleep(50L); //wait for subscription //when some non-status-change event is emitted events.next(new InstanceRegisteredEvent(instance.getId(), instance.getVersion(), instance.getRegistration())); //then should not update verify(updater, never()).updateInfo(instance.getId()); //when status-change event is emitted events.next(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown())); //then should update verify(updater, times(1)).updateInfo(instance.getId()); //when endpoints-detected event is emitted clearInvocations(updater); events.next(new InstanceEndpointsDetectedEvent(instance.getId(), instance.getVersion(), Endpoints.empty())); //then should update verify(updater, times(1)).updateInfo(instance.getId()); //when registration updated event is emitted clearInvocations(updater); events.next( new InstanceRegistrationUpdatedEvent(instance.getId(), instance.getVersion(), instance.getRegistration())); //then should update verify(updater, times(1)).updateInfo(instance.getId()); //when registered event is emitted but the trigger has been stopped trigger.stop(); clearInvocations(updater); events.next(new InstanceRegisteredEvent(instance.getId(), instance.getVersion(), instance.getRegistration())); //then should not update verify(updater, never()).updateInfo(instance.getId()); }