Add try/catch blocks to prevent client shutdown errors from preventing

Broker shutdown.
This commit is contained in:
Timothy Bish 2014-08-08 12:34:38 -04:00
parent 999385ea53
commit 4a2af3ab07
1 changed files with 36 additions and 24 deletions

View File

@ -41,7 +41,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public abstract class JmsTransactionTestSupport extends TestSupport implements MessageListener { public abstract class JmsTransactionTestSupport extends TestSupport implements MessageListener {
@ -61,8 +61,8 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
protected BrokerService broker; protected BrokerService broker;
// for message listener test // for message listener test
private List<Message> unackMessages = new ArrayList<Message>(MESSAGE_COUNT); private final List<Message> unackMessages = new ArrayList<Message>(MESSAGE_COUNT);
private List<Message> ackMessages = new ArrayList<Message>(MESSAGE_COUNT); private final List<Message> ackMessages = new ArrayList<Message>(MESSAGE_COUNT);
private boolean resendPhase; private boolean resendPhase;
public JmsTransactionTestSupport() { public JmsTransactionTestSupport() {
@ -75,9 +75,10 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see junit.framework.TestCase#setUp() * @see junit.framework.TestCase#setUp()
*/ */
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
broker = createBroker(); broker = createBroker();
broker.start(); broker.start();
@ -119,19 +120,29 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see junit.framework.TestCase#tearDown() * @see junit.framework.TestCase#tearDown()
*/ */
@Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
LOG.info("Closing down connection"); LOG.info("Closing down connection");
session.close(); try {
session = null; session.close();
connection.close(); session = null;
connection = null; connection.close();
broker.stop(); connection = null;
broker.waitUntilStopped(); } catch (Exception e) {
broker = null; 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."); LOG.info("Connection closed.");
} }
@ -140,7 +151,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the messages are received. * Sends a batch of messages and validates that the messages are received.
* *
* @throws Exception * @throws Exception
*/ */
public void testSendReceiveTransactedBatches() throws Exception { public void testSendReceiveTransactedBatches() throws Exception {
@ -174,7 +185,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the rollbacked message was * Sends a batch of messages and validates that the rollbacked message was
* not consumed. * not consumed.
* *
* @throws Exception * @throws Exception
*/ */
public void testSendRollback() throws Exception { public void testSendRollback() throws Exception {
@ -295,7 +306,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the message sent before * Sends a batch of messages and validates that the message sent before
* session close is not consumed. * session close is not consumed.
* *
* @throws Exception * @throws Exception
*/ */
public void testSendSessionAndConnectionClose() throws Exception { public void testSendSessionAndConnectionClose() throws Exception {
@ -343,7 +354,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the rollbacked message was * Sends a batch of messages and validates that the rollbacked message was
* redelivered. * redelivered.
* *
* @throws Exception * @throws Exception
*/ */
public void testReceiveRollback() throws Exception { public void testReceiveRollback() throws Exception {
@ -394,7 +405,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the rollbacked message was * Sends a batch of messages and validates that the rollbacked message was
* redelivered. * redelivered.
* *
* @throws Exception * @throws Exception
*/ */
public void testReceiveTwoThenRollback() throws Exception { public void testReceiveTwoThenRollback() throws Exception {
@ -448,7 +459,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the rollbacked message was * Sends a batch of messages and validates that the rollbacked message was
* not consumed. * not consumed.
* *
* @throws Exception * @throws Exception
*/ */
public void testSendReceiveWithPrefetchOne() throws Exception { public void testSendReceiveWithPrefetchOne() throws Exception {
@ -479,7 +490,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Perform the test that validates if the rollbacked message was redelivered * Perform the test that validates if the rollbacked message was redelivered
* multiple times. * multiple times.
* *
* @throws Exception * @throws Exception
*/ */
public void testReceiveTwoThenRollbackManyTimes() throws Exception { public void testReceiveTwoThenRollbackManyTimes() throws Exception {
@ -491,7 +502,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Sends a batch of messages and validates that the rollbacked message was * Sends a batch of messages and validates that the rollbacked message was
* not consumed. This test differs by setting the message prefetch to one. * not consumed. This test differs by setting the message prefetch to one.
* *
* @throws Exception * @throws Exception
*/ */
public void testSendRollbackWithPrefetchOfOne() throws Exception { public void testSendRollbackWithPrefetchOfOne() throws Exception {
@ -503,7 +514,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
* Sends a batch of messages and and validates that the rollbacked message * Sends a batch of messages and and validates that the rollbacked message
* was redelivered. This test differs by setting the message prefetch to * was redelivered. This test differs by setting the message prefetch to
* one. * one.
* *
* @throws Exception * @throws Exception
*/ */
public void testReceiveRollbackWithPrefetchOfOne() throws Exception { public void testReceiveRollbackWithPrefetchOfOne() throws Exception {
@ -514,7 +525,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Tests if the messages can still be received if the consumer is closed * Tests if the messages can still be received if the consumer is closed
* (session is not closed). * (session is not closed).
* *
* @throws Exception see http://jira.codehaus.org/browse/AMQ-143 * @throws Exception see http://jira.codehaus.org/browse/AMQ-143
*/ */
public void testCloseConsumerBeforeCommit() throws Exception { public void testCloseConsumerBeforeCommit() throws Exception {
@ -605,7 +616,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Recreates the connection. * Recreates the connection.
* *
* @throws JMSException * @throws JMSException
*/ */
protected void reconnect() throws Exception { protected void reconnect() throws Exception {
@ -622,7 +633,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
/** /**
* Recreates the connection. * Recreates the connection.
* *
* @throws JMSException * @throws JMSException
*/ */
protected void reconnectSession() throws JMSException { protected void reconnectSession() throws JMSException {
@ -671,6 +682,7 @@ public abstract class JmsTransactionTestSupport extends TestSupport implements M
reconnect(); reconnect();
} }
@Override
public void onMessage(Message message) { public void onMessage(Message message) {
if (!resendPhase) { if (!resendPhase) {
unackMessages.add(message); unackMessages.add(message);