Miscellaneous fixes

* Fix `MiscellaneousTests` to extend `ActiveMQMultiContextTests`
to let it to close ActiveMQ connection factory in the end of test
* Make `RequestReplyScenariosWithTempReplyQueuesTests` more robust
closing `DefaultMessageListenerContainer` and `ExecutorService`
in the end of tests
* Fix new Sonar smells
* Rework some SQL calls in the `JdbcMessageStore` to note expose a
`PreparedStatement` API
* Fix JavaDoc in the `CorrelationHandlerSpec`
This commit is contained in:
Artem Bilan
2021-03-26 12:39:00 -04:00
parent 7abbe30c81
commit f2009271dc
8 changed files with 90 additions and 108 deletions

View File

@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.integration.jms.ActiveMQMultiContextTests;
import org.springframework.integration.test.condition.LongRunningTest;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.util.StopWatch;
@@ -32,9 +33,10 @@ import org.springframework.util.StopWatch;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*/
@LongRunningTest
public class MiscellaneousTests {
public class MiscellaneousTests extends ActiveMQMultiContextTests {
/**
* Asserts that receive-timeout is honored even if
@@ -43,20 +45,22 @@ public class MiscellaneousTests {
*/
@Test
public void testTimeoutHonoringWhenRequestsQueuedUp() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("honor-timeout.xml", this.getClass());
final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
final CountDownLatch latch = new CountDownLatch(3);
final AtomicInteger replies = new AtomicInteger();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 3; i++) {
this.exchange(latch, gateway, replies);
try (ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("honor-timeout.xml", getClass())) {
final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
final CountDownLatch latch = new CountDownLatch(3);
final AtomicInteger replies = new AtomicInteger();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 3; i++) {
this.exchange(latch, gateway, replies);
}
latch.await();
stopWatch.stop();
assertThat(stopWatch.getTotalTimeMillis()).isLessThanOrEqualTo(18000);
assertThat(replies.get()).isEqualTo(1);
}
latch.await();
stopWatch.stop();
assertThat(stopWatch.getTotalTimeMillis() <= 18000).isTrue();
assertThat(replies.get()).isEqualTo(1);
context.close();
}

View File

@@ -104,15 +104,16 @@ public class RequestReplyScenariosWithTempReplyQueuesTests extends ActiveMQMulti
@Test
public void messageCorrelationBasedOnRequestCorrelationIdTimedOutFirstReply() throws Exception {
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
try (ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("producer-temp-reply-consumers.xml", this.getClass())) {
new ClassPathXmlApplicationContext("producer-temp-reply-consumers.xml", getClass())) {
RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
final Destination requestDestination = context.getBean("siOutQueue", Destination.class);
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
;
dmlc.setConnectionFactory(connectionFactory);
dmlc.setDestination(requestDestination);
dmlc.setMessageListener((SessionAwareMessageListener<Message>) (message, session) -> {
@@ -155,6 +156,10 @@ public class RequestReplyScenariosWithTempReplyQueuesTests extends ActiveMQMulti
Thread.sleep(1000);
assertThat(gateway.exchange(new GenericMessage<>("bar")).getPayload()).isEqualTo("bar");
}
finally {
dmlc.stop();
dmlc.destroy();
}
}
/**
@@ -202,11 +207,11 @@ public class RequestReplyScenariosWithTempReplyQueuesTests extends ActiveMQMulti
@Test
public void testConcurrently() throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(10);
try (ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("mult-producer-and-consumers-temp-reply.xml", this.getClass())) {
new ClassPathXmlApplicationContext("multi-producer-and-consumers-temp-reply.xml", this.getClass())) {
final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
ExecutorService executor = Executors.newFixedThreadPool(10);
final int testNumbers = 30;
final CountDownLatch latch = new CountDownLatch(testNumbers);
final AtomicInteger failures = new AtomicInteger();
@@ -239,6 +244,8 @@ public class RequestReplyScenariosWithTempReplyQueuesTests extends ActiveMQMulti
assertThat(mismatches.get()).isEqualTo(0);
assertThat(failures.get()).isEqualTo(0);
assertThat(timeouts.get()).isEqualTo(0);
}
finally {
executor.shutdownNow();
}
}