You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2014/05/26 16:31:58 UTC

svn commit: r1597595 - /qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java

Author: kwall
Date: Mon May 26 14:31:57 2014
New Revision: 1597595

URL: http://svn.apache.org/r1597595
Log:
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.

Modified:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java?rev=1597595&r1=1597594&r2=1597595&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java Mon May 26 14:31:57 2014
@@ -63,17 +63,19 @@ public abstract class TransactionTimeout
     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 TransactionTimeout
         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 TransactionTimeout
      * 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()



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org