summaryrefslogtreecommitdiff
path: root/qpid/java/systests/src
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2014-05-26 14:31:57 +0000
committerKeith Wall <kwall@apache.org>2014-05-26 14:31:57 +0000
commitd14fd4dc8626c61b9e364fa501c3627c3a26c99d (patch)
tree9d86390137a0cd050ae308ee0a51dd4e9dbba2c3 /qpid/java/systests/src
parent9195c91f87bda61140f0c3fda0e420803c900abd (diff)
downloadqpid-python-d14fd4dc8626c61b9e364fa501c3627c3a26c99d.tar.gz
NO-JIRA: [Java Broker Tests] Fix race condition in TransactionTimeoutTests meaning observations of test members could yield NPE
* Reordered so that the exception listener's latch is decremented only after members for linked exception message and linked exception code. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1597595 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests/src')
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java49
1 files changed, 23 insertions, 26 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
index 721dc027c6..98fe29f826 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
@@ -63,17 +63,19 @@ public abstract class TransactionTimeoutTestCase extends QpidBrokerTestCase impl
protected Queue _queue;
protected MessageConsumer _consumer;
protected MessageProducer _producer;
- private CountDownLatch _exceptionLatch = new CountDownLatch(1);
- protected AtomicInteger _exceptionCount = new AtomicInteger(0);
- protected String _message;
protected Exception _exception;
- protected AMQConstant _code;
+
+ private final CountDownLatch _exceptionListenerLatch = new CountDownLatch(1);
+ private final AtomicInteger _exceptionCount = new AtomicInteger(0);
+ private volatile AMQConstant _linkedExceptionCode;
+ private volatile String _linkedExceptionMessage;
/**
* Subclasses must implement this to configure transaction timeout parameters.
*/
protected abstract void configure() throws Exception;
-
+
+ @Override
protected void setUp() throws Exception
{
// Configure timeouts
@@ -100,18 +102,6 @@ public abstract class TransactionTimeoutTestCase extends QpidBrokerTestCase impl
producer();
consumer();
}
-
- protected void tearDown() throws Exception
- {
- try
- {
- _con.close();
- }
- finally
- {
- super.tearDown();
- }
- }
/**
* Create a transacted persistent message producer session.
@@ -218,26 +208,33 @@ public abstract class TransactionTimeoutTestCase extends QpidBrokerTestCase impl
* Checks that the correct exception was thrown and was received
* by the listener with a 506 error code.
*/
- protected void check(String reason)throws InterruptedException
+ protected void check(String reason) throws InterruptedException
{
- assertTrue("Should have caught exception in listener", _exceptionLatch.await(1, TimeUnit.SECONDS));
assertNotNull("Should have thrown exception to client", _exception);
- assertTrue("Exception message should contain '" + reason + "': " + _message, _message.contains(reason + " transaction timed out"));
- assertNotNull("Exception should have an error code", _code);
- assertEquals("Error code should be 506", AMQConstant.RESOURCE_ERROR, _code);
+
+ assertTrue("Should have caught exception in listener", _exceptionListenerLatch.await(1, TimeUnit.SECONDS));
+ assertNotNull("Linked exception message should not be null", _linkedExceptionMessage);
+ assertTrue("Linked exception message '" + _linkedExceptionMessage + "' should contain '" + reason + "'",
+ _linkedExceptionMessage.contains(reason + " transaction timed out"));
+ assertNotNull("Linked exception should have an error code", _linkedExceptionCode);
+ assertEquals("Linked exception error code should be 506", AMQConstant.RESOURCE_ERROR, _linkedExceptionCode);
}
/** @see javax.jms.ExceptionListener#onException(javax.jms.JMSException) */
+ @Override
public void onException(JMSException jmse)
{
- _exceptionLatch.countDown();
- _exceptionCount.incrementAndGet();
+ if (jmse.getLinkedException() != null)
+ {
+ _linkedExceptionMessage = jmse.getLinkedException().getMessage();
+ }
- _message = jmse.getLinkedException().getMessage();
if (jmse.getLinkedException() instanceof AMQException)
{
- _code = ((AMQException) jmse.getLinkedException()).getErrorCode();
+ _linkedExceptionCode = ((AMQException) jmse.getLinkedException()).getErrorCode();
}
+ _exceptionCount.incrementAndGet();
+ _exceptionListenerLatch.countDown();
}
protected int getNumberOfDeliveredExceptions()