use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method consumerSubscribedToErrorChannel.
@Test
public void consumerSubscribedToErrorChannel() throws InterruptedException {
TestApplicationContext context = TestUtils.createTestApplicationContext();
QueueChannel errorChannel = new QueueChannel();
context.registerChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, errorChannel);
final CountDownLatch latch = new CountDownLatch(1);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
latch.countDown();
return null;
}
};
PollingConsumer endpoint = new PollingConsumer(errorChannel, handler);
endpoint.setBeanFactory(mock(BeanFactory.class));
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
errorChannel.send(new ErrorMessage(new RuntimeException("test-exception")));
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals("handler should have received error message", 0, latch.getCount());
context.stop();
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class CGLibProxyChannelTests method testProxyExecutor.
@Test
public void testProxyExecutor() throws Exception {
assertTrue(AopUtils.isCglibProxy(this.executorChannel));
final AtomicReference<Message<?>> message = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.executorChannel.subscribe(m -> {
message.set(m);
latch.countDown();
});
this.executorChannel.send(new GenericMessage<>("foo"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(message.get());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class CGLibProxyChannelTests method testProxyPubSubWithExec.
@Test
public void testProxyPubSubWithExec() throws Exception {
assertTrue(AopUtils.isCglibProxy(this.publishSubscribeChannel));
final AtomicReference<Message<?>> message = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.publishSubscribeChannel.subscribe(m -> {
message.set(m);
latch.countDown();
});
this.publishSubscribeChannel.send(new GenericMessage<>("foo"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(message.get());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ReactiveStreamsConsumerTests method testReactiveStreamsConsumerDirectChannel.
@Test
@SuppressWarnings("unchecked")
public void testReactiveStreamsConsumerDirectChannel() throws InterruptedException {
DirectChannel testChannel = new DirectChannel();
Subscriber<Message<?>> testSubscriber = (Subscriber<Message<?>>) Mockito.mock(Subscriber.class);
BlockingQueue<Message<?>> messages = new LinkedBlockingQueue<>();
willAnswer(i -> {
messages.put(i.getArgument(0));
return null;
}).given(testSubscriber).onNext(any(Message.class));
ReactiveStreamsConsumer reactiveConsumer = new ReactiveStreamsConsumer(testChannel, testSubscriber);
reactiveConsumer.setBeanFactory(mock(BeanFactory.class));
reactiveConsumer.afterPropertiesSet();
reactiveConsumer.start();
Message<?> testMessage = new GenericMessage<>("test");
testChannel.send(testMessage);
ArgumentCaptor<Subscription> subscriptionArgumentCaptor = ArgumentCaptor.forClass(Subscription.class);
verify(testSubscriber).onSubscribe(subscriptionArgumentCaptor.capture());
Subscription subscription = subscriptionArgumentCaptor.getValue();
subscription.request(1);
Message<?> message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
reactiveConsumer.stop();
try {
testChannel.send(testMessage);
fail("MessageDeliveryException");
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
}
reactiveConsumer.start();
subscription.request(1);
testMessage = new GenericMessage<>("test2");
testChannel.send(testMessage);
message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
verify(testSubscriber, never()).onError(any(Throwable.class));
verify(testSubscriber, never()).onComplete();
assertTrue(messages.isEmpty());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ReactiveStreamsConsumerTests method testReactiveStreamsConsumerPollableChannel.
@Test
@SuppressWarnings("unchecked")
public void testReactiveStreamsConsumerPollableChannel() throws InterruptedException {
QueueChannel testChannel = new QueueChannel();
Subscriber<Message<?>> testSubscriber = (Subscriber<Message<?>>) Mockito.mock(Subscriber.class);
BlockingQueue<Message<?>> messages = new LinkedBlockingQueue<>();
willAnswer(i -> {
messages.put(i.getArgument(0));
return null;
}).given(testSubscriber).onNext(any(Message.class));
ReactiveStreamsConsumer reactiveConsumer = new ReactiveStreamsConsumer(testChannel, testSubscriber);
reactiveConsumer.setBeanFactory(mock(BeanFactory.class));
reactiveConsumer.afterPropertiesSet();
reactiveConsumer.start();
Message<?> testMessage = new GenericMessage<>("test");
testChannel.send(testMessage);
ArgumentCaptor<Subscription> subscriptionArgumentCaptor = ArgumentCaptor.forClass(Subscription.class);
verify(testSubscriber).onSubscribe(subscriptionArgumentCaptor.capture());
Subscription subscription = subscriptionArgumentCaptor.getValue();
subscription.request(1);
Message<?> message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
reactiveConsumer.stop();
testChannel.send(testMessage);
reactiveConsumer.start();
verify(testSubscriber, times(2)).onSubscribe(subscriptionArgumentCaptor.capture());
subscription = subscriptionArgumentCaptor.getValue();
subscription.request(2);
Message<?> testMessage2 = new GenericMessage<>("test2");
testChannel.send(testMessage2);
message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage2, message);
verify(testSubscriber, never()).onError(any(Throwable.class));
verify(testSubscriber, never()).onComplete();
assertTrue(messages.isEmpty());
}
Aggregations