use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class JdbcOutboundGatewayParserTests method testDefaultMaxMessagesPerPollIsSet.
@Test
public void testDefaultMaxMessagesPerPollIsSet() {
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
PollingConsumer pollingConsumer = this.context.getBean(PollingConsumer.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
Object source = accessor.getPropertyValue("handler");
accessor = new DirectFieldAccessor(source);
// JdbcPollingChannelAdapter
source = accessor.getPropertyValue("poller");
accessor = new DirectFieldAccessor(source);
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
assertEquals("maxRowsPerPoll should default to 1", Integer.valueOf(1), maxRowsPerPoll);
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class ChatMessageOutboundChannelAdapterParserTests method withHeaderMapper.
@SuppressWarnings("rawtypes")
@Test
public void withHeaderMapper() throws Exception {
Object pollingConsumer = context.getBean("withHeaderMapper");
assertTrue(pollingConsumer instanceof PollingConsumer);
assertEquals(headerMapper, TestUtils.getPropertyValue(pollingConsumer, "handler.headerMapper"));
MessageChannel channel = context.getBean("outboundEventChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload("hello").setHeader(XmppHeaders.TO, "oleg").setHeader("foobar", "foobar").build();
XMPPConnection connection = context.getBean("testConnection", XMPPConnection.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("oleg", xmppMessage.getTo().toString());
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
return null;
}).when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
channel.send(message);
verify(connection, times(1)).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
Mockito.reset(connection);
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class ChatMessageOutboundChannelAdapterParserTests method testPollingConsumer.
@Test
public void testPollingConsumer() {
Object pollingConsumer = context.getBean("withHeaderMapper");
QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(pollingConsumer, "inputChannel");
assertEquals("outboundPollingChannel", channel.getComponentName());
assertTrue(pollingConsumer instanceof PollingConsumer);
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class PresenceOutboundChannelAdapterParserTests method testRosterEventOutboundChannelAdapterParserAsPollingConsumer.
@Test
public void testRosterEventOutboundChannelAdapterParserAsPollingConsumer() {
Object pollingConsumer = context.getBean("pollingOutboundRosterAdapter");
assertTrue(pollingConsumer instanceof PollingConsumer);
AbstractXmppConnectionAwareMessageHandler handler = (AbstractXmppConnectionAwareMessageHandler) TestUtils.getPropertyValue(pollingConsumer, "handler");
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class ContentEnricherTests method replyChannelReplyTimingOut.
/**
* In this test a {@link Target} message is passed into a {@link ContentEnricher}.
* The Enricher passes the message to a "request-channel" that is backed by a
* {@link QueueChannel}. The consumer of the "request-channel" takes a long
* time to execute, longer actually than the specified "replyTimeout" set on
* the {@link ContentEnricher}.
*
* Due to the occurring replyTimeout, a Null replyMessage is returned and because
* "requiresReply" is set to "true" on the {@link ContentEnricher}, a
* {@link ReplyRequiredException} is raised.
*/
@Test
public void replyChannelReplyTimingOut() throws Exception {
final long requestTimeout = 500L;
final long replyTimeout = 100L;
final DirectChannel replyChannel = new DirectChannel();
final QueueChannel requestChannel = new QueueChannel(1);
final ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setReplyChannel(replyChannel);
enricher.setOutputChannel(new NullChannel());
enricher.setRequestTimeout(requestTimeout);
enricher.setReplyTimeout(replyTimeout);
final ExpressionFactoryBean expressionFactoryBean = new ExpressionFactoryBean("payload");
expressionFactoryBean.setSingleton(false);
expressionFactoryBean.afterPropertiesSet();
final Map<String, Expression> expressions = new HashMap<String, Expression>();
expressions.put("name", new LiteralExpression("cartman"));
expressions.put("child.name", expressionFactoryBean.getObject());
enricher.setPropertyExpressions(expressions);
enricher.setRequiresReply(true);
enricher.setBeanName("Enricher");
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
final AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
fail(e.getMessage());
}
return new Target("child");
}
};
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
final PollingConsumer consumer = new PollingConsumer(requestChannel, handler);
final TestErrorHandler errorHandler = new TestErrorHandler();
consumer.setTrigger(new PeriodicTrigger(0));
consumer.setErrorHandler(errorHandler);
consumer.setTaskScheduler(taskScheduler);
consumer.setBeanFactory(mock(BeanFactory.class));
consumer.afterPropertiesSet();
consumer.start();
final Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
try {
enricher.handleMessage(requestMessage);
} catch (ReplyRequiredException e) {
assertEquals("No reply produced by handler 'Enricher', and its 'requiresReply' property is set to true.", e.getMessage());
return;
}
fail("ReplyRequiredException expected.");
}
Aggregations