use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AbstractCorrelatingMessageHandlerTests method testReapWithChangeInSameMillisecond.
@Test
public void testReapWithChangeInSameMillisecond() throws Exception {
MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor();
AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp);
handler.setReleaseStrategy(group -> true);
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class);
Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class);
forceComplete.setAccessible(true);
GenericMessage<String> secondMessage = new GenericMessage<String>("bar");
mgs.addMessagesToGroup("foo", new GenericMessage<String>("foo"), secondMessage);
MessageGroup group = mgs.getMessageGroup("foo");
// remove a message
mgs.removeMessagesFromGroup("foo", secondMessage);
// force lastModified to be the same
MessageGroup groupNow = mgs.getMessageGroup("foo");
new DirectFieldAccessor(group).setPropertyValue("lastModified", groupNow.getLastModified());
forceComplete.invoke(handler, group);
Message<?> message = outputChannel.receive(0);
assertNotNull(message);
Collection<?> payload = (Collection<?>) message.getPayload();
assertEquals(1, payload.size());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class BarrierMessageHandlerTests method testReplyBeforeRequest.
@Test
public void testReplyBeforeRequest() throws Exception {
final BarrierMessageHandler handler = new BarrierMessageHandler(10000);
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> handler.trigger(MessageBuilder.withPayload("bar").setCorrelationId("foo").build()));
Map<?, ?> suspensions = TestUtils.getPropertyValue(handler, "suspensions", Map.class);
int n = 0;
while (n++ < 100 && suspensions.size() == 0) {
Thread.sleep(100);
}
assertTrue("suspension did not appear in time", n < 100);
handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
Message<?> received = outputChannel.receive(10000);
assertNotNull(received);
List<?> result = (ArrayList<?>) received.getPayload();
assertEquals("foo", result.get(0));
assertEquals("bar", result.get(1));
assertEquals(0, suspensions.size());
exec.shutdownNow();
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class BarrierMessageHandlerTests method testLateReply.
@Test
public void testLateReply() throws Exception {
final BarrierMessageHandler handler = new BarrierMessageHandler(0);
QueueChannel outputChannel = new QueueChannel();
QueueChannel discardChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.setDiscardChannelName("discards");
handler.setChannelResolver(s -> discardChannel);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
final CountDownLatch latch = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
latch.countDown();
});
Map<?, ?> suspensions = TestUtils.getPropertyValue(handler, "suspensions", Map.class);
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("suspension not removed", 0, suspensions.size());
Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
final Message<String> triggerMessage = MessageBuilder.withPayload("bar").setCorrelationId("foo").build();
handler.trigger(triggerMessage);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger).error(captor.capture());
assertThat(captor.getValue(), allOf(containsString("Suspending thread timed out or did not arrive within timeout for:"), containsString("payload=bar")));
assertEquals(0, suspensions.size());
Message<?> discard = discardChannel.receive(0);
assertSame(discard, triggerMessage);
handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
assertEquals(0, suspensions.size());
exec.shutdownNow();
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class ExpressionEvaluatingCorrelationStrategyTests method testCorrelationStrategyWithAtBeanExpression.
@Test
public void testCorrelationStrategyWithAtBeanExpression() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("expression-evaluating-correlation-with-bf.xml", this.getClass());
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
Message<?> message = MessageBuilder.withPayload("foo").setSequenceNumber(1).setSequenceSize(1).build();
inputChannel.send(message);
Message<?> reply = outputChannel.receive(0);
assertNotNull(reply);
context.close();
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class AsyncHandlerTests method testMessagingException.
@Test
public void testMessagingException() {
QueueChannel errorChannel = new QueueChannel();
Message<String> message = MessageBuilder.withPayload("foo").setErrorChannel(errorChannel).build();
this.handler.handleMessage(message);
assertNull(this.output.receive(0));
this.whichTest = 2;
this.latch.countDown();
Message<?> received = errorChannel.receive(10000);
assertNotNull(received);
assertThat(received.getPayload(), instanceOf(MessagingException.class));
assertSame(message, ((MessagingException) received.getPayload()).getFailedMessage());
assertNull(this.failedCallbackException);
}
Aggregations