use of org.springframework.integration.jms.JmsOutboundGateway.ReplyContainerProperties in project spring-integration by spring-projects.
the class JmsOutboundGatewayTests method testReplyContainerRecovery.
@SuppressWarnings("serial")
@Test
public void testReplyContainerRecovery() throws Exception {
JmsOutboundGateway gateway = new JmsOutboundGateway();
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
gateway.setConnectionFactory(connectionFactory);
gateway.setRequestDestinationName("foo");
gateway.setUseReplyContainer(true);
ReplyContainerProperties replyContainerProperties = new ReplyContainerProperties();
final List<Throwable> errors = new ArrayList<Throwable>();
ExecutorService exec = Executors.newFixedThreadPool(10);
ErrorHandlingTaskExecutor errorHandlingTaskExecutor = new ErrorHandlingTaskExecutor(exec, t -> {
errors.add(t);
throw new RuntimeException(t);
});
replyContainerProperties.setTaskExecutor(errorHandlingTaskExecutor);
replyContainerProperties.setRecoveryInterval(100L);
gateway.setReplyContainerProperties(replyContainerProperties);
final Connection connection = mock(Connection.class);
final AtomicInteger connectionAttempts = new AtomicInteger();
doAnswer(invocation -> {
int theCount = connectionAttempts.incrementAndGet();
if (theCount > 1 && theCount < 4) {
throw new JmsException("bar") {
};
}
return connection;
}).when(connectionFactory).createConnection();
Session session = mock(Session.class);
when(connection.createSession(false, 1)).thenReturn(session);
MessageConsumer consumer = mock(MessageConsumer.class);
when(session.createConsumer(any(Destination.class), isNull())).thenReturn(consumer);
when(session.createTemporaryQueue()).thenReturn(mock(TemporaryQueue.class));
final Message message = mock(Message.class);
final AtomicInteger count = new AtomicInteger();
doAnswer(invocation -> {
int theCount = count.incrementAndGet();
if (theCount > 1 && theCount < 4) {
throw new JmsException("foo") {
};
}
if (theCount > 4) {
Thread.sleep(100);
return null;
}
return message;
}).when(consumer).receive(anyLong());
when(message.getJMSCorrelationID()).thenReturn("foo");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize();
beanFactory.registerSingleton("taskScheduler", taskScheduler);
gateway.setBeanFactory(beanFactory);
gateway.afterPropertiesSet();
gateway.start();
try {
int n = 0;
while (n++ < 100 && count.get() < 5) {
Thread.sleep(100);
}
assertTrue(count.get() > 4);
assertEquals(0, errors.size());
} finally {
gateway.stop();
exec.shutdownNow();
}
}
use of org.springframework.integration.jms.JmsOutboundGateway.ReplyContainerProperties in project spring-integration by spring-projects.
the class JmsOutboundGatewayTests method testContainerBeanNameWhenNoGatewayBeanName.
@Test
public void testContainerBeanNameWhenNoGatewayBeanName() {
JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setConnectionFactory(mock(ConnectionFactory.class));
gateway.setRequestDestinationName("foo");
gateway.setUseReplyContainer(true);
gateway.setReplyContainerProperties(new ReplyContainerProperties());
gateway.setBeanFactory(mock(BeanFactory.class));
gateway.afterPropertiesSet();
assertEquals("JMS_OutboundGateway@" + ObjectUtils.getIdentityHexString(gateway) + ".replyListener", TestUtils.getPropertyValue(gateway, "replyContainer.beanName"));
}
Aggregations