Miscellaneous tests and Sonar fixes
* Fix complexity in the `DefaultJmsHeaderMapper` according Sonar report * Optimize all JMS tests to rely on a shared `ActiveMQConnectionFactory` resource and disable JMX & statistics for embedded ActiveMQ broker * Increase timeout for some sporadically failing tests
This commit is contained in:
@@ -36,7 +36,7 @@ import org.springframework.jms.connection.CachingConnectionFactory;
|
||||
public abstract class ActiveMQMultiContextTests {
|
||||
|
||||
public static final ActiveMQConnectionFactory amqFactory =
|
||||
new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
|
||||
new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false&broker.useJmx=false&broker.enableStatistics=false");
|
||||
|
||||
public static final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(amqFactory);
|
||||
|
||||
@@ -44,12 +44,12 @@ public abstract class ActiveMQMultiContextTests {
|
||||
public static void startUp() throws Exception {
|
||||
amqFactory.setTrustAllPackages(true);
|
||||
connectionFactory.setCacheConsumers(false);
|
||||
connectionFactory.createConnection().close();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutDown() {
|
||||
public static void shutDown() throws Exception {
|
||||
connectionFactory.destroy();
|
||||
amqFactory.createConnection().close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import javax.jms.Session;
|
||||
import javax.jms.TemporaryQueue;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -155,8 +154,7 @@ public class JmsOutboundGatewayTests extends ActiveMQMultiContextTests {
|
||||
|
||||
@Test
|
||||
public void testConnectionBreakOnReplyMessageIdCorrelation() {
|
||||
CachingConnectionFactory connectionFactory1 =
|
||||
new CachingConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"));
|
||||
CachingConnectionFactory connectionFactory1 = new CachingConnectionFactory(ActiveMQMultiContextTests.amqFactory);
|
||||
connectionFactory1.setCacheConsumers(false);
|
||||
final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
||||
gateway.setConnectionFactory(connectionFactory1);
|
||||
@@ -171,8 +169,7 @@ public class JmsOutboundGatewayTests extends ActiveMQMultiContextTests {
|
||||
gateway.afterPropertiesSet();
|
||||
gateway.start();
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
CachingConnectionFactory connectionFactory2 =
|
||||
new CachingConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"));
|
||||
CachingConnectionFactory connectionFactory2 = new CachingConnectionFactory(ActiveMQMultiContextTests.amqFactory);
|
||||
connectionFactory2.setCacheConsumers(false);
|
||||
JmsTemplate template = new JmsTemplate(connectionFactory2);
|
||||
template.setReceiveTimeout(10000);
|
||||
@@ -203,8 +200,7 @@ public class JmsOutboundGatewayTests extends ActiveMQMultiContextTests {
|
||||
|
||||
@Test
|
||||
public void testConnectionBreakOnReplyCustomCorrelation() {
|
||||
CachingConnectionFactory connectionFactory1 =
|
||||
new CachingConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"));
|
||||
CachingConnectionFactory connectionFactory1 = new CachingConnectionFactory(ActiveMQMultiContextTests.amqFactory);
|
||||
connectionFactory1.setCacheConsumers(false);
|
||||
final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
||||
gateway.setConnectionFactory(connectionFactory1);
|
||||
@@ -220,8 +216,7 @@ public class JmsOutboundGatewayTests extends ActiveMQMultiContextTests {
|
||||
gateway.afterPropertiesSet();
|
||||
gateway.start();
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
CachingConnectionFactory connectionFactory2 =
|
||||
new CachingConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"));
|
||||
CachingConnectionFactory connectionFactory2 = new CachingConnectionFactory(ActiveMQMultiContextTests.amqFactory);
|
||||
connectionFactory2.setCacheConsumers(false);
|
||||
JmsTemplate template = new JmsTemplate(connectionFactory2);
|
||||
template.setReceiveTimeout(10000);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class OutboundGatewayConnectionTests {
|
||||
exec.execute(() -> {
|
||||
latch1.countDown();
|
||||
try {
|
||||
reply.set(gateway.handleRequestMessage(new GenericMessage<String>("foo")));
|
||||
reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo")));
|
||||
}
|
||||
finally {
|
||||
latch2.countDown();
|
||||
@@ -98,7 +98,7 @@ public class OutboundGatewayConnectionTests {
|
||||
javax.jms.Message request = template.receive(requestQueue1);
|
||||
assertThat(request).isNotNull();
|
||||
final javax.jms.Message jmsReply = request;
|
||||
template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply);
|
||||
template.send(request.getJMSReplyTo(), session -> jmsReply);
|
||||
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(reply.get()).isNotNull();
|
||||
|
||||
|
||||
@@ -109,11 +109,8 @@
|
||||
</bean>
|
||||
|
||||
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="vm://localhost?broker.persistent=false" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="targetConnectionFactory"
|
||||
value="#{T(org.springframework.integration.jms.ActiveMQMultiContextTests).amqFactory}"/>
|
||||
<property name="cacheProducers" value="true" />
|
||||
<property name="cacheConsumers" value="true" />
|
||||
<property name="sessionCacheSize" value="10" />
|
||||
|
||||
@@ -20,11 +20,8 @@
|
||||
</bean>
|
||||
|
||||
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="targetConnectionFactory"
|
||||
value="#{T(org.springframework.integration.jms.ActiveMQMultiContextTests).amqFactory}"/>
|
||||
<property name="cacheProducers" value="true" />
|
||||
<property name="cacheConsumers" value="true" />
|
||||
<property name="sessionCacheSize" value="10" />
|
||||
|
||||
Reference in New Issue
Block a user