use of org.springframework.integration.endpoint.ReactiveStreamsConsumer in project spring-integration by spring-projects.
the class ReactiveStreamsConsumerTests method testReactiveStreamsConsumerFluxMessageChannel.
@Test
public void testReactiveStreamsConsumerFluxMessageChannel() throws InterruptedException {
FluxMessageChannel testChannel = new FluxMessageChannel();
List<Message<?>> result = new LinkedList<>();
CountDownLatch stopLatch = new CountDownLatch(2);
MessageHandler messageHandler = m -> {
result.add(m);
stopLatch.countDown();
};
MessageHandler testSubscriber = new MethodInvokingMessageHandler(messageHandler, (String) null);
ReactiveStreamsConsumer reactiveConsumer = new ReactiveStreamsConsumer(testChannel, testSubscriber);
reactiveConsumer.setBeanFactory(mock(BeanFactory.class));
reactiveConsumer.afterPropertiesSet();
reactiveConsumer.start();
Message<?> testMessage = new GenericMessage<>("test");
testChannel.send(testMessage);
reactiveConsumer.stop();
try {
testChannel.send(testMessage);
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
}
reactiveConsumer.start();
Message<?> testMessage2 = new GenericMessage<>("test2");
testChannel.send(testMessage2);
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2));
}
Aggregations