qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1232785 - in /qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java
Date Wed, 18 Jan 2012 08:33:39 GMT
Author: kwall
Date: Wed Jan 18 08:33:39 2012
New Revision: 1232785

URL: http://svn.apache.org/viewvc?rev=1232785&view=rev
Log:
QPID-3756: ManagedConnectionMBeanTest.testChannels occasionally fails on 0-10 spawned profiles

This problem is caused by the connection mbean being deregistered too late (as the TCP/IP
socket)
is closed, thus creating a race between the client using JMX to observe connection state,
and the
unregistering of the bean.  This patch changes the 0-10 code path to unregister the bean on
receipt
of ConnectionClose and before ConnectionCloseOkay is sent to the client.

Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java?rev=1232785&r1=1232784&r2=1232785&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
(original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
Wed Jan 18 08:33:39 2012
@@ -62,6 +62,8 @@ import org.apache.qpid.transport.Executi
 import org.apache.qpid.transport.Method;
 import org.apache.qpid.transport.ProtocolEvent;
 import org.apache.qpid.transport.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ServerConnection extends Connection implements Managable, AMQConnectionModel,
LogSubject, AuthorizationHolder
 {
@@ -123,6 +125,7 @@ public class ServerConnection extends Co
             {
                 _virtualHost.getConnectionRegistry().deregisterConnection(this);
             }
+            unregisterConnectionMbean();
         }
 
         if (state == State.CLOSED)
@@ -161,15 +164,7 @@ public class ServerConnection extends Co
 
         initialiseStatistics();
 
-        try
-        {
-            _mBean = new ServerConnectionMBean(this);
-            _mBean.register();
-        }
-        catch (JMException jme)
-        {
-            log.error("Unable to create mBean for ServerConnection",jme);
-        }
+        registerConnectionMbean();
     }
 
     public void setConnectionConfig(final ConnectionConfig config)
@@ -285,11 +280,7 @@ public class ServerConnection extends Co
     public void close(AMQConstant cause, String message) throws AMQException
     {
         closeSubscriptions();
-        if (_mBean != null)
-        {
-            _mBean.unregister();
-            _mBean = null;
-        }
+        unregisterConnectionMbean();
         ConnectionCloseCode replyCode = ConnectionCloseCode.NORMAL;
         try
         {
@@ -433,11 +424,6 @@ public class ServerConnection extends Co
     public void closed()
     {
         closeSubscriptions();
-        if (_mBean != null)
-        {
-            _mBean.unregister();
-            _mBean = null;
-        }
         super.closed();
     }
 
@@ -483,4 +469,30 @@ public class ServerConnection extends Co
             _mBean.notifyClients("Channel count (" + channelsCount + ") has reached the threshold
value");
         }
     }
+
+    private void registerConnectionMbean()
+    {
+        try
+        {
+            _mBean = new ServerConnectionMBean(this);
+            _mBean.register();
+        }
+        catch (JMException jme)
+        {
+            log.error("Unable to register mBean for ServerConnection", jme);
+        }
+    }
+
+    private void unregisterConnectionMbean()
+    {
+        if (_mBean != null)
+        {
+            if (log.isDebugEnabled())
+            {
+                log.debug("Unregistering mBean for ServerConnection" + _mBean);
+            }
+            _mBean.unregister();
+            _mBean = null;
+        }
+    }
 }

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java?rev=1232785&r1=1232784&r2=1232785&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java
Wed Jan 18 08:33:39 2012
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+
 import javax.jms.Connection;
 import javax.jms.Destination;
 import javax.jms.Message;
@@ -37,9 +38,13 @@ import org.apache.qpid.client.AMQSession
 import org.apache.qpid.management.common.mbeans.ManagedConnection;
 import org.apache.qpid.test.utils.JMXTestUtils;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ManagedConnectionMBeanTest extends QpidBrokerTestCase
 {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagedConnectionMBeanTest.class);
+
     /**
      * JMX helper.
      */
@@ -120,9 +125,10 @@ public class ManagedConnectionMBeanTest 
 
         _connection.close();
 
+        LOGGER.debug("Querying JMX for number of open connections");
         connections = _jmxUtils.getManagedConnections("test");
         assertNotNull("Connection MBean is not found", connections);
-        assertEquals("Unexpected number of connection mbeans", 0, connections.size());
+        assertEquals("Unexpected number of connection mbeans after connection closed", 0,
connections.size());
     }
 
     public void testCommit() throws Exception



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


Mime
View raw message