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 2011/09/23 17:40:44 UTC

svn commit: r1174842 - in /qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/transport/ systests/src/main/java/org/apache/qpid/test/unit/transacted/

Author: kwall
Date: Fri Sep 23 15:40:43 2011
New Revision: 1174842

URL: http://svn.apache.org/viewvc?rev=1174842&view=rev
Log:
QPID-3332: Separate open/idle transaction timeout tests to remove the possibility of an unexpected log message. Remove TransactionTimeoutConfigTest as this only duplicated tests aleady performed by TransactionTimeoutTest.

Removed:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutConfigurationTest.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java?rev=1174842&r1=1174841&r2=1174842&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java Fri Sep 23 15:40:43 2011
@@ -645,7 +645,7 @@ public class ServerSession extends Sessi
             // Log a warning on idle or open transactions
             if (idleWarn > 0L && idleTime > idleWarn)
             {
-                CurrentActor.get().message(getLogSubject(), ChannelMessages.IDLE_TXN(openTime));
+                CurrentActor.get().message(getLogSubject(), ChannelMessages.IDLE_TXN(idleTime));
                 _logger.warn("IDLE TRANSACTION ALERT " + getLogSubject().toString() + " " + idleTime + " ms");
             }
             else if (openWarn > 0L && openTime > openWarn)

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java?rev=1174842&r1=1174841&r2=1174842&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java Fri Sep 23 15:40:43 2011
@@ -30,6 +30,8 @@ public class TransactionTimeoutDisabledT
     {
         // Setup housekeeping every second
         setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
+
+        // No transaction timeout configuration.
     }
 
     public void testProducerIdleCommit() throws Exception
@@ -47,7 +49,7 @@ public class TransactionTimeoutDisabledT
             fail("Should have succeeded");
         }
         
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
         
         monitor(0, 0);
     }
@@ -65,7 +67,7 @@ public class TransactionTimeoutDisabledT
             fail("Should have succeeded");
         }
         
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
         
         monitor(0, 0);
     }

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java?rev=1174842&r1=1174841&r2=1174842&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java Fri Sep 23 15:40:43 2011
@@ -30,152 +30,125 @@ package org.apache.qpid.test.unit.transa
  */
 public class TransactionTimeoutTest extends TransactionTimeoutTestCase
 {
-    public void testProducerIdle() throws Exception
+
+    protected void configure() throws Exception
     {
-        try
+        // Setup housekeeping every second
+        setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
+
+        if (getName().contains("ProducerIdle"))
         {
-            sleep(2.0f);
-    
-            _psession.commit();
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500");
         }
-        catch (Exception e)
+        else if (getName().contains("ProducerOpen"))
         {
-            fail("Should have succeeded");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0");
         }
-        
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
-        
-        monitor(0, 0);
-    }
-    
-    public void testProducerIdleCommit() throws Exception
-    {
-        try
+        else
         {
-            send(5, 0);
-            
-            sleep(2.0f);
-    
-            _psession.commit();
-            fail("should fail");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
+            setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000");
         }
-        catch (Exception e)
-        {
-            _exception = e;
-        }
-        
-        monitor(5, 0);
-        
-        check(IDLE);
     }
-    
-    public void testProducerOpenCommit() throws Exception
+
+    public void testProducerIdle() throws Exception
     {
-        try
-        {
-            send(6, 0.5f);
-    
-            _psession.commit();
-            fail("should fail");
-        }
-        catch (Exception e)
-        {
-            _exception = e;
-        }
-        
-        monitor(0, 10);
-        
-        check(OPEN);
+        sleep(2.0f);
+
+        _psession.commit();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
+        monitor(0, 0);
     }
-    
-    public void testProducerIdleCommitTwice() throws Exception
+
+    public void testProducerIdleCommit() throws Exception
     {
+        send(5, 0);
+        // Idle for more than idleClose to generate idle-warns and cause a close.
+        sleep(2.0f);
+
         try
         {
-            send(5, 0);
-            
-            sleep(1.0f);
-            
-            _psession.commit();
-            
-            send(5, 0);
-            
-            sleep(2.0f);
-    
             _psession.commit();
-            fail("should fail");
+            fail("Exception not thrown");
         }
         catch (Exception e)
         {
             _exception = e;
         }
-        
+
         monitor(10, 0);
-        
+
         check(IDLE);
     }
-    
-    public void testProducerOpenCommitTwice() throws Exception
+
+    public void testProducerIdleCommitTwice() throws Exception
     {
+        send(5, 0);
+        // Idle for less than idleClose to generate idle-warns
+        sleep(1.0f);
+
+        _psession.commit();
+
+        send(5, 0);
+        // Now idle for more than idleClose to generate more idle-warns and cause a close.
+        sleep(2.0f);
+
         try
         {
-            send(5, 0);
-            
-            sleep(1.0f);
-            
-            _psession.commit();
-            
-            send(6, 0.5f);
-    
             _psession.commit();
-            fail("should fail");
+            fail("Exception not thrown");
         }
         catch (Exception e)
         {
             _exception = e;
         }
-        
-        // the presistent store generates more idle messages?
-        monitor(isBrokerStorePersistent() ? 10 : 5, 10);
-        
-        check(OPEN);
+
+        monitor(15, 0);
+
+        check(IDLE);
     }
-    
+
     public void testProducerIdleRollback() throws Exception
     {
+        send(5, 0);
+        // Now idle for more than idleClose to generate more idle-warns and cause a close.
+        sleep(2.0f);
         try
         {
-            send(5, 0);
-            
-            sleep(2.0f);
-    
             _psession.rollback();
-            fail("should fail");
+            fail("Exception not thrown");
         }
         catch (Exception e)
         {
             _exception = e;
         }
-        
-        monitor(5, 0);
-        
+
+        monitor(10, 0);
+
         check(IDLE);
     }
-    
+
     public void testProducerIdleRollbackTwice() throws Exception
     {
+        send(5, 0);
+        // Idle for less than idleClose to generate idle-warns
+        sleep(1.0f);
+        _psession.rollback();
+        send(5, 0);
+        // Now idle for more than idleClose to generate more idle-warns and cause a close.
+        sleep(2.0f);
         try
         {
-            send(5, 0);
-            
-            sleep(1.0f);
-            
-            _psession.rollback();
-            
-            send(5, 0);
-            
-            sleep(2.0f);
-    
             _psession.rollback();
             fail("should fail");
         }
@@ -183,153 +156,153 @@ public class TransactionTimeoutTest exte
         {
             _exception = e;
         }
-        
-        monitor(10, 0);
+
+        monitor(15, 0);
         
         check(IDLE);
     }
-    
-    public void testConsumerCommitClose() throws Exception
+
+    public void testProducerOpenCommit() throws Exception
     {
         try
         {
-            send(1, 0);
-    
+            // Sleep between sends to cause open warns and then cause a close.
+            send(6, 0.5f);
             _psession.commit();
-    
-            expect(1, 0);
-            
-            _csession.commit();
-            
-            sleep(3.0f);
-    
-            _csession.close();
+            fail("Exception not thrown");
         }
         catch (Exception e)
         {
-            fail("should have succeeded: " + e.getMessage());
+            _exception = e;
         }
-        
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
-        
-        monitor(0, 0);
+
+        monitor(0, 10);
+
+        check(OPEN);
     }
     
-    public void testConsumerIdleReceiveCommit() throws Exception
+    public void testProducerOpenCommitTwice() throws Exception
     {
+        send(5, 0);
+        sleep(1.0f);
+        _psession.commit();
+
         try
         {
-            send(1, 0);
-    
+            // Now sleep between sends to cause open warns and then cause a close.
+            send(6, 0.5f);
             _psession.commit();
-    
-            sleep(2.0f);
-            
-            expect(1, 0);
-            
-            sleep(2.0f);
-    
-            _csession.commit();
+            fail("Exception not thrown");
         }
         catch (Exception e)
         {
-            fail("Should have succeeded");
+            _exception = e;
         }
+
+        monitor(0, 10);
         
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
-        
+        check(OPEN);
+    }
+
+    public void testConsumerCommitClose() throws Exception
+    {
+        send(1, 0);
+
+        _psession.commit();
+
+        expect(1, 0);
+
+        _csession.commit();
+
+        sleep(3.0f);
+
+        _csession.close();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
         monitor(0, 0);
     }
     
+    public void testConsumerIdleReceiveCommit() throws Exception
+    {
+        send(1, 0);
+
+        _psession.commit();
+
+        sleep(2.0f);
+
+        expect(1, 0);
+
+        sleep(2.0f);
+
+        _csession.commit();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
+        monitor(0, 0);
+    }
+
     public void testConsumerIdleCommit() throws Exception
     {
-        try
-        {
-            send(1, 0);
-    
-            _psession.commit();
-    
-            expect(1, 0);
-            
-            sleep(2.0f);
-    
-            _csession.commit();
-        }
-        catch (Exception e)
-        {
-            fail("Should have succeeded");
-        }
-        
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
-        
+        send(1, 0);
+
+        _psession.commit();
+
+        expect(1, 0);
+
+        sleep(2.0f);
+
+        _csession.commit();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
         monitor(0, 0);
     }
     
     public void testConsumerIdleRollback() throws Exception
     {
-        try
-        {
-            send(1, 0);
-    
-            _psession.commit();
-            
-            expect(1, 0);
-            
-            sleep(2.0f);
-    
-            _csession.rollback();
-        }
-        catch (Exception e)
-        {
-            fail("Should have succeeded");
-        }
-        
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
-        
+        send(1, 0);
+
+        _psession.commit();
+
+        expect(1, 0);
+
+        sleep(2.0f);
+
+        _csession.rollback();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
         monitor(0, 0);
     }
-    
+
     public void testConsumerOpenCommit() throws Exception
     {
-        try
-        {
-            send(1, 0);
-    
-            _psession.commit();
-            
-            sleep(3.0f);
-    
-            _csession.commit();
-        }
-        catch (Exception e)
-        {
-            fail("Should have succeeded");
-        }
-        
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
-        
+        send(1, 0);
+
+        _psession.commit();
+
+        sleep(3.0f);
+
+        _csession.commit();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
         monitor(0, 0);
     }
     
     public void testConsumerOpenRollback() throws Exception
     {
-        try
-        {
-            send(1, 0);
-    
-            _psession.commit();
-    
-            sleep(3.0f);
-    
-            _csession.rollback();
-        }
-        catch (Exception e)
-        {
-            fail("Should have succeeded");
-        }
-        
-        assertTrue("Listener should not have received exception", _caught.getCount() == 1);
+        send(1, 0);
         
+        _psession.commit();
+
+        sleep(3.0f);
+
+        _csession.rollback();
+
+        assertEquals("Listener should not have received exception", 0, getNumberOfDeliveredExceptions());
+
         monitor(0, 0);
     }
 }

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=1174842&r1=1174841&r2=1174842&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 Fri Sep 23 15:40:43 2011
@@ -23,6 +23,7 @@ package org.apache.qpid.test.unit.transa
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jms.DeliveryMode;
 import javax.jms.ExceptionListener;
@@ -49,7 +50,7 @@ import org.apache.qpid.util.LogMonitor;
 /**
  * The {@link TestCase} for transaction timeout testing.
  */
-public class TransactionTimeoutTestCase extends QpidBrokerTestCase implements ExceptionListener
+public abstract class TransactionTimeoutTestCase extends QpidBrokerTestCase implements ExceptionListener
 {
     public static final String VIRTUALHOST = "test";
     public static final String TEXT = "0123456789abcdefghiforgettherest";
@@ -64,31 +65,16 @@ public class TransactionTimeoutTestCase 
     protected Queue _queue;
     protected MessageConsumer _consumer;
     protected MessageProducer _producer;
-    protected CountDownLatch _caught = new CountDownLatch(1);
+    private CountDownLatch _exceptionLatch = new CountDownLatch(1);
+    protected AtomicInteger _exceptionCount = new AtomicInteger(0);
     protected String _message;
     protected Exception _exception;
     protected AMQConstant _code;
-    
-    protected void configure() throws Exception
-    {
-        // Setup housekeeping every second
-        setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
-        
-        /*
-         * Set transaction timout properties. The XML in the virtualhosts configuration is as follows:
-         * 
-         *  <transactionTimeout>
-         *      <openWarn>1000</openWarn>
-         *      <openClose>2000</openClose>
-         *      <idleWarn>500</idleWarn>
-         *      <idleClose>1500</idleClose>
-         *  </transactionTimeout>
-         */
-        setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
-        setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
-        setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
-        setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000");
-    }
+
+    /**
+     * Subclasses must implement this to configure transaction timeout parameters.
+     */
+    protected abstract void configure() throws Exception;
         
     protected void setUp() throws Exception
     {
@@ -233,7 +219,7 @@ public class TransactionTimeoutTestCase 
      */
     protected void check(String reason)throws InterruptedException
     {
-        assertTrue("Should have caught exception in listener", _caught.await(1, TimeUnit.SECONDS));
+        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);
@@ -243,11 +229,18 @@ public class TransactionTimeoutTestCase 
     /** @see javax.jms.ExceptionListener#onException(javax.jms.JMSException) */
     public void onException(JMSException jmse)
     {
-        _caught.countDown();
+        _exceptionLatch.countDown();
+        _exceptionCount.incrementAndGet();
+
         _message = jmse.getLinkedException().getMessage();
         if (jmse.getLinkedException() instanceof AMQException)
         {
             _code = ((AMQException) jmse.getLinkedException()).getErrorCode();
         }
     }
+
+    protected int getNumberOfDeliveredExceptions()
+    {
+        return _exceptionCount.get();
+    }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org