package com.bsb.btm; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Stephane Nicoll */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath*:/META-INF/app-test/bootstrap-test.xml"}) public class RollbackOnlyMessageListenerTest { @Autowired private MessageSender messageSender; @Test public void sendMessage() throws InterruptedException { // Sending the message to this queue will process the message in the current transaction and // throw an expected exception. After 3 times (see ConnectionFactory) the message will be send // to the dlq. The DlqMessageListener listens to it and will log something. messageSender.sendMessage("Bla Bla Bla", "queue/queueB", false); // Give some time to the asynchronous issue to occur. Thread.sleep(5000); } @Test public void sendMessageWithProcessingInRequiresNew() throws InterruptedException { // This test case reproduces the issue. The processing of the message happens in a REQUIRES_NEW // transaction. When the exception is thrown, the rollback occurs as expected but for whatever // reason, the rollback ends in some infinite loop (acknowledgment issue?). Of course the // exact same setup is used for both cases. Only the queue name is different messageSender.sendMessage("Bla Bla Bla", "queue/queueA", false); // Give some time to the asynchronous issue to occur. Thread.sleep(5000); } }