Skip to content

Commit

Permalink
Add try/catch blocks to prevent client shutdown errors from preventing
Browse files Browse the repository at this point in the history
Broker shutdown.
  • Loading branch information
tabish121 committed Aug 8, 2014
1 parent 999385e commit 4a2af3a
Showing 1 changed file with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.slf4j.LoggerFactory;

/**
*
*
*/
public abstract class JmsTransactionTestSupport extends TestSupport implements MessageListener {

Expand All @@ -61,8 +61,8 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
protected BrokerService broker;

// for message listener test
private List<Message> unackMessages = new ArrayList<Message>(MESSAGE_COUNT);
private List<Message> ackMessages = new ArrayList<Message>(MESSAGE_COUNT);
private final List<Message> unackMessages = new ArrayList<Message>(MESSAGE_COUNT);
private final List<Message> ackMessages = new ArrayList<Message>(MESSAGE_COUNT);
private boolean resendPhase;

public JmsTransactionTestSupport() {
Expand All @@ -75,9 +75,10 @@ public JmsTransactionTestSupport(String name) {

/*
* (non-Javadoc)
*
*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
broker = createBroker();
broker.start();
Expand Down Expand Up @@ -119,19 +120,29 @@ protected BrokerService createBroker() throws Exception, URISyntaxException {

/*
* (non-Javadoc)
*
*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
LOG.info("Closing down connection");

session.close();
session = null;
connection.close();
connection = null;
broker.stop();
broker.waitUntilStopped();
broker = null;
try {
session.close();
session = null;
connection.close();
connection = null;
} catch (Exception e) {
LOG.info("Caught exception while closing resources.");
}

try {
broker.stop();
broker.waitUntilStopped();
broker = null;
} catch (Exception e) {
LOG.info("Caught exception while shutting down the Broker", e);
}

LOG.info("Connection closed.");
}
Expand All @@ -140,7 +151,7 @@ protected void tearDown() throws Exception {

/**
* Sends a batch of messages and validates that the messages are received.
*
*
* @throws Exception
*/
public void testSendReceiveTransactedBatches() throws Exception {
Expand Down Expand Up @@ -174,7 +185,7 @@ protected void messageSent() throws Exception {
/**
* Sends a batch of messages and validates that the rollbacked message was
* not consumed.
*
*
* @throws Exception
*/
public void testSendRollback() throws Exception {
Expand Down Expand Up @@ -295,7 +306,7 @@ public void testSendSessionClose() throws Exception {
/**
* Sends a batch of messages and validates that the message sent before
* session close is not consumed.
*
*
* @throws Exception
*/
public void testSendSessionAndConnectionClose() throws Exception {
Expand Down Expand Up @@ -343,7 +354,7 @@ public void testSendSessionAndConnectionClose() throws Exception {
/**
* Sends a batch of messages and validates that the rollbacked message was
* redelivered.
*
*
* @throws Exception
*/
public void testReceiveRollback() throws Exception {
Expand Down Expand Up @@ -394,7 +405,7 @@ public void testReceiveRollback() throws Exception {
/**
* Sends a batch of messages and validates that the rollbacked message was
* redelivered.
*
*
* @throws Exception
*/
public void testReceiveTwoThenRollback() throws Exception {
Expand Down Expand Up @@ -448,7 +459,7 @@ public void testReceiveTwoThenRollback() throws Exception {
/**
* Sends a batch of messages and validates that the rollbacked message was
* not consumed.
*
*
* @throws Exception
*/
public void testSendReceiveWithPrefetchOne() throws Exception {
Expand Down Expand Up @@ -479,7 +490,7 @@ public void testSendReceiveWithPrefetchOne() throws Exception {
/**
* Perform the test that validates if the rollbacked message was redelivered
* multiple times.
*
*
* @throws Exception
*/
public void testReceiveTwoThenRollbackManyTimes() throws Exception {
Expand All @@ -491,7 +502,7 @@ public void testReceiveTwoThenRollbackManyTimes() throws Exception {
/**
* Sends a batch of messages and validates that the rollbacked message was
* not consumed. This test differs by setting the message prefetch to one.
*
*
* @throws Exception
*/
public void testSendRollbackWithPrefetchOfOne() throws Exception {
Expand All @@ -503,7 +514,7 @@ public void testSendRollbackWithPrefetchOfOne() throws Exception {
* Sends a batch of messages and and validates that the rollbacked message
* was redelivered. This test differs by setting the message prefetch to
* one.
*
*
* @throws Exception
*/
public void testReceiveRollbackWithPrefetchOfOne() throws Exception {
Expand All @@ -514,7 +525,7 @@ public void testReceiveRollbackWithPrefetchOfOne() throws Exception {
/**
* Tests if the messages can still be received if the consumer is closed
* (session is not closed).
*
*
* @throws Exception see http://jira.codehaus.org/browse/AMQ-143
*/
public void testCloseConsumerBeforeCommit() throws Exception {
Expand Down Expand Up @@ -605,7 +616,7 @@ protected List<String> assertReceivedObjectMessageWithListBody(Message message)

/**
* Recreates the connection.
*
*
* @throws JMSException
*/
protected void reconnect() throws Exception {
Expand All @@ -622,7 +633,7 @@ protected void reconnect() throws Exception {

/**
* Recreates the connection.
*
*
* @throws JMSException
*/
protected void reconnectSession() throws JMSException {
Expand Down Expand Up @@ -671,6 +682,7 @@ public void testMessageListener() throws Exception {
reconnect();
}

@Override
public void onMessage(Message message) {
if (!resendPhase) {
unackMessages.add(message);
Expand Down

0 comments on commit 4a2af3a

Please sign in to comment.