You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2012/06/07 12:51:20 UTC

svn commit: r1347565 - in /qpid/branches/java-config-and-management/qpid/java: broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/ broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ broker-plugins/jmx/src/test/ broker-plugins/...

Author: robbie
Date: Thu Jun  7 10:51:19 2012
New Revision: 1347565

URL: http://svn.apache.org/viewvc?rev=1347565&view=rev
Log:
Add unit test for ConnectionMBean, update ConnectionMBean system test, add additional log statements in JMX registry, remove old management layers JMX registry

Added:
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
Removed:
    qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java
Modified:
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBean.java
    qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
    qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java
    qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
    qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java
    qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
    qpid/branches/java-config-and-management/qpid/java/test-profiles/Excludes

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java Thu Jun  7 10:51:19 2012
@@ -312,6 +312,8 @@ public class JMXManagedObjectRegistry im
                 }
                 catch (NotBoundException nbe)
                 {
+                    // TODO consider if we want to keep new logging
+                    _log.error("Failed to unbind jmxrmi", nbe);
                     //ignore
                 }
 
@@ -435,6 +437,8 @@ public class JMXManagedObjectRegistry im
     //Stops the JMXConnectorServer and RMIRegistry, then unregisters any remaining MBeans from the MBeanServer
     public void close()
     {
+        _log.debug("close() called");
+
         if (_cs != null)
         {
             // Stopping the JMX ConnectorServer
@@ -445,7 +449,7 @@ public class JMXManagedObjectRegistry im
             }
             catch (IOException e)
             {
-                _log.error("Exception while closing the JMX ConnectorServer: " + e.getMessage());
+                _log.error("Exception while closing the JMX ConnectorServer: ",  e);
             }
         }
         
@@ -455,11 +459,15 @@ public class JMXManagedObjectRegistry im
             CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("RMI Registry", _jmxPortRegistryServer));
             try
             {
-                UnicastRemoteObject.unexportObject(_rmiRegistry, false);
+                boolean success = UnicastRemoteObject.unexportObject(_rmiRegistry, false);
+                if (!success)
+                {
+                    _log.warn("Failed to unexport object " + _rmiRegistry);
+                }
             }
             catch (NoSuchObjectException e)
             {
-                _log.error("Exception while closing the RMI Registry: " + e.getMessage());
+                _log.error("Exception while closing the RMI Registry: ", e);
             }
         }
         

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBean.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBean.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBean.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBean.java Thu Jun  7 10:51:19 2012
@@ -151,12 +151,12 @@ public class ConnectionMBean extends Abs
 
     public void commitTransactions(int channelId) throws JMException
     {
-        // TODO - Commiting transaction on a channel makes *no* sense
+        throw buildUnsupportedException();
     }
 
     public void rollbackTransactions(int channelId) throws JMException
     {
-        // TODO - rolling back a transaction on a channel makes *no* sense
+        throw buildUnsupportedException();
     }
 
     public void closeConnection() throws Exception
@@ -164,7 +164,6 @@ public class ConnectionMBean extends Abs
         getConfiguredObject().delete();
     }
 
-
     public synchronized boolean isStatisticsEnabled()
     {
         return true;
@@ -175,4 +174,12 @@ public class ConnectionMBean extends Abs
         // TODO - Implement setStatisticsEnabled
         updateStats();
     }
+
+    private JMException buildUnsupportedException() throws JMException
+    {
+        String msg = "Operation not supported";
+        JMException jmException = new JMException(msg);
+        jmException.initCause(new UnsupportedOperationException(msg));
+        return jmException;
+    }
 }

Modified: qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java Thu Jun  7 10:51:19 2012
@@ -145,7 +145,7 @@ public class VirtualHostMBean extends AM
                 }
                 else
                 {
-
+                    // TODO
                 }
 
             }

Added: qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java?rev=1347565&view=auto
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java (added)
+++ qpid/branches/java-config-and-management/qpid/java/broker-plugins/jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/ConnectionMBeanTest.java Thu Jun  7 10:51:19 2012
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.server.jmx.mbeans;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.Date;
+
+import javax.management.JMException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.qpid.management.common.mbeans.ManagedConnection;
+import org.apache.qpid.server.jmx.ManagedObject;
+import org.apache.qpid.server.jmx.ManagedObjectRegistry;
+import org.apache.qpid.server.model.Connection;
+import org.apache.qpid.server.model.Session;
+import org.apache.qpid.server.model.Statistics;
+
+public class ConnectionMBeanTest extends TestCase
+{
+    private ConnectionMBean _connectionMBean;
+    private Connection _mockConnection;
+    private VirtualHostMBean _mockVirtualHostMBean;
+    private ManagedObjectRegistry _mockManagedObjectRegistry;
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        _mockConnection = mock(Connection.class);
+        _mockVirtualHostMBean = mock(VirtualHostMBean.class);
+
+        _mockManagedObjectRegistry = mock(ManagedObjectRegistry.class);
+        when(_mockVirtualHostMBean.getRegistry()).thenReturn(_mockManagedObjectRegistry);
+
+        _connectionMBean = new ConnectionMBean(_mockConnection, _mockVirtualHostMBean);
+    }
+
+    public void testMBeanRegistersItself() throws Exception
+    {
+        ConnectionMBean connectionMBean = new ConnectionMBean(_mockConnection, _mockVirtualHostMBean);
+        verify(_mockManagedObjectRegistry).registerObject(connectionMBean);
+    }
+
+    public void testCloseConnection() throws Exception
+    {
+        _connectionMBean.closeConnection();
+        verify(_mockConnection).delete();
+    }
+
+    public void testCommitTransactions()
+    {
+        try
+        {
+            _connectionMBean.commitTransactions(0);
+            fail("Exception not thrown");
+        }
+        catch(JMException e)
+        {
+            assertTrue("Cause should be an UnsupportedOperationException", e.getCause() instanceof UnsupportedOperationException);
+        }
+    }
+
+    public void testRollbackTransactions()
+    {
+        try
+        {
+            _connectionMBean.rollbackTransactions(0);
+            fail("Exception not thrown");
+        }
+        catch(JMException e)
+        {
+            assertTrue("Cause should be an UnsupportedOperationException", e.getCause() instanceof UnsupportedOperationException);
+        }
+    }
+
+    public void testChannelsWithSingleTransactionalSession() throws Exception
+    {
+        int channelId = 10;
+        int unacknowledgedMessages = 2;
+        long localTransactionBegins = 1;
+        boolean transactional = true;
+
+        Session mockSession = createMockedSession(channelId, unacknowledgedMessages, localTransactionBegins);
+
+        when(_mockConnection.getSessions()).thenReturn(Collections.singletonList(mockSession));
+
+        TabularData table = _connectionMBean.channels();
+        assertEquals("Unexpected number of rows in table", 1, table.size());
+
+        final CompositeData row = table.get(new Integer[] {channelId} );
+        assertRow(row, channelId, unacknowledgedMessages, transactional);
+    }
+
+    public void testChannelsWithSingleNonTransactionalSession() throws Exception
+    {
+        int channelId = 10;
+        int unacknowledgedMessages = 2;
+        long localTransactionBegins = 0;
+        boolean transactional  = false;
+
+        Session mockSession = createMockedSession(channelId, unacknowledgedMessages, localTransactionBegins);
+
+        when(_mockConnection.getSessions()).thenReturn(Collections.singletonList(mockSession));
+
+        TabularData table = _connectionMBean.channels();
+        assertEquals("Unexpected number of rows in table", 1, table.size());
+
+        final CompositeData row = table.get(new Integer[] {channelId} );
+        assertRow(row, channelId, unacknowledgedMessages, transactional);
+    }
+
+    public void testParentObjectIsVirtualHost()
+    {
+        ManagedObject parent = _connectionMBean.getParentObject();
+        assertEquals(_mockVirtualHostMBean, parent);
+    }
+
+    public void testGetObjectInstanceName()
+    {
+        String remoteAddress = "testRemoteAddress";
+        String quotedRemoteAddress = "\"testRemoteAddress\"";
+        when(_mockConnection.getAttribute(Connection.REMOTE_ADDRESS)).thenReturn(remoteAddress);
+        String objectInstanceName = _connectionMBean.getObjectInstanceName();
+        assertEquals(quotedRemoteAddress, objectInstanceName);
+    }
+
+    public void testGetAuthorizedId() throws Exception
+    {
+        assertAttribute("authorizedId", "testAuthorizedId", Connection.PRINCIPAL);
+    }
+
+    public void testGetVersion() throws Exception
+    {
+        assertAttribute("version", "testVersion", Connection.CLIENT_VERSION);
+    }
+
+    public void testGetRemoteAddress() throws Exception
+    {
+        assertAttribute("remoteAddress", "testRemoteAddress", Connection.REMOTE_ADDRESS);
+    }
+
+    public void testGetLastIoTime()
+    {
+        Statistics mockStatistics = mock(Statistics.class);
+        when(_mockConnection.getStatistics()).thenReturn(mockStatistics);
+        when(mockStatistics.getStatistic(Connection.LAST_IO_TIME)).thenReturn(1L);
+
+        Object actualValue = _connectionMBean.getLastIoTime();
+        assertEquals("Unexpected lastIoTime", new Date(1L), actualValue);
+    }
+
+    public void testGetMaximumNumberOfChannels() throws Exception
+    {
+        assertAttribute("maximumNumberOfChannels", 10l, Connection.SESSION_COUNT_LIMIT);
+    }
+
+    public void testIsStatisticsEnabledAlwaysTrue() throws Exception
+    {
+        assertTrue(_connectionMBean.isStatisticsEnabled());
+    }
+
+    private void assertAttribute(String jmxAttributeName, Object expectedValue, String underlyingAttributeName) throws Exception
+    {
+        when(_mockConnection.getAttribute(underlyingAttributeName)).thenReturn(expectedValue);
+
+        Object actualValue = PropertyUtils.getSimpleProperty(_connectionMBean, jmxAttributeName);
+        assertEquals("Unexpected " + jmxAttributeName, expectedValue, actualValue);
+    }
+
+    private void assertRow(final CompositeData row, int channelId, int unacknowledgedMessages, boolean isTransactional)
+    {
+        assertNotNull("No row for channel id " + channelId, row);
+        assertEquals("Unexpected channel id", channelId, row.get(ManagedConnection.CHAN_ID));
+        assertEquals("Unexpected transactional flag", isTransactional, row.get(ManagedConnection.TRANSACTIONAL));
+        assertEquals("Unexpected unacknowledged message count", unacknowledgedMessages, row.get(ManagedConnection.UNACKED_COUNT));
+    }
+
+    private Session createMockedSession(int channelId, int unacknowledgedMessages, long localTransactionBegins)
+    {
+        Session mockSession = mock(Session.class);
+        Statistics mockSessionStatistics = mock(Statistics.class);
+        when(mockSessionStatistics.getStatistic(Session.LOCAL_TRANSACTION_BEGINS)).thenReturn(localTransactionBegins);
+        when(mockSessionStatistics.getStatistic(Session.UNACKNOWLEDGED_MESSAGES)).thenReturn(unacknowledgedMessages);
+
+        when(mockSession.getStatistics()).thenReturn(mockSessionStatistics);
+        when(mockSession.getAttribute(Session.CHANNEL_ID)).thenReturn(channelId);
+        return mockSession;
+    }
+}

Modified: qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Statistics.java Thu Jun  7 10:51:19 2012
@@ -1,8 +1,4 @@
-package org.apache.qpid.server.model;
-
-import java.util.Collection;
-
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -18,6 +14,11 @@ import java.util.Collection;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+package org.apache.qpid.server.model;
+
+import java.util.Collection;
+
 public interface Statistics
 {
     Collection<String> getStatisticNames();

Modified: qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java Thu Jun  7 10:51:19 2012
@@ -21,12 +21,10 @@
 package org.apache.qpid.server.registry;
 
 import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.model.Broker;
 import org.osgi.framework.BundleContext;
 
 import org.apache.qpid.AMQException;
 import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.management.JMXManagedObjectRegistry;
 import org.apache.qpid.server.management.NoopManagedObjectRegistry;
 
 import java.io.File;
@@ -46,6 +44,10 @@ public class ConfigurationFileApplicatio
     @Override
     protected void initialiseManagedObjectRegistry() throws AMQException
     {
+          // TODO the following block was commented out to stop loading both
+          // management implementations, this method should be removed as the
+          // old management layer is extracted.
+
 //        if (getConfiguration().getManagementEnabled())
 //        {
 //            setManagedObjectRegistry(new JMXManagedObjectRegistry());

Modified: qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagedConnectionMBeanTest.java Thu Jun  7 10:51:19 2012
@@ -18,10 +18,7 @@
  */
 package org.apache.qpid.management.jmx;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.client.AMQSession;
+import org.apache.commons.lang.StringUtils;
 import org.apache.qpid.common.QpidProperties;
 import org.apache.qpid.management.common.mbeans.ManagedConnection;
 import org.apache.qpid.test.utils.JMXTestUtils;
@@ -29,14 +26,14 @@ import org.apache.qpid.test.utils.QpidBr
 
 import javax.jms.Connection;
 import javax.jms.Destination;
+import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
 import javax.jms.Session;
-import javax.jms.TextMessage;
 import javax.management.JMException;
 import javax.management.openmbean.CompositeDataSupport;
 import javax.management.openmbean.TabularData;
+
 import java.io.IOException;
 import java.util.Date;
 import java.util.Iterator;
@@ -44,21 +41,17 @@ import java.util.List;
 
 public class ManagedConnectionMBeanTest extends QpidBrokerTestCase
 {
-    private static final Logger LOGGER = LoggerFactory.getLogger(ManagedConnectionMBeanTest.class);
+    private static final String VIRTUAL_HOST_NAME = "test";
 
-    /**
-     * JMX helper.
-     */
     private JMXTestUtils _jmxUtils;
     private Connection _connection;
 
     public void setUp() throws Exception
     {
         _jmxUtils = new JMXTestUtils(this);
-        _jmxUtils.setUp();
+        _jmxUtils.setUp(); // modifies broker config therefore must be done before super.setUp()
         super.setUp();
         _jmxUtils.open();
-        _connection = getConnection();
     }
 
     public void tearDown() throws Exception
@@ -70,209 +63,119 @@ public class ManagedConnectionMBeanTest 
         super.tearDown();
     }
 
-    public void testChannels() throws Exception
+    public void testTransactedSession() throws Exception
     {
-        final String queueName = getTestQueueName();
-
+        _connection = getConnection();
         final Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
-        final Destination destination = session.createQueue(queueName);
-        final MessageConsumer consumer = session.createConsumer(destination);
 
-        final int numberOfMessages = 2;
-        sendMessage(session, destination, numberOfMessages);
-        _connection.start();
+        receiveTwoMessagesWithoutCommit(session);
 
-        for (int i = 0; i < numberOfMessages; i++)
-        {
-            final Message m = consumer.receive(1000l);
-            assertNotNull("Message " + i + " is not received", m);
-        }
+        final ManagedConnection mBean = getConnectionMBean();
 
-        List<ManagedConnection> connections = _jmxUtils.getManagedConnections("test");
-        assertNotNull("Connection MBean is not found", connections);
-        assertEquals("Unexpected number of connection mbeans", 1, connections.size());
-        final ManagedConnection mBean = connections.get(0);
-        assertNotNull("Connection MBean is null", mBean);
-
-        TabularData channelsData = mBean.channels();
-        assertNotNull("Channels data are null", channelsData);
-        assertEquals("Unexpected number of rows in channel table", 1, channelsData.size());
-
-        final Iterator<CompositeDataSupport> rowItr = (Iterator<CompositeDataSupport>) channelsData.values().iterator();
-        final CompositeDataSupport row = rowItr.next();
-        Number unackCount = (Number) row.get(ManagedConnection.UNACKED_COUNT);
+        // check session details in the row
+        final CompositeDataSupport row = getTheOneChannelRow(mBean);
+        final Number unackCount = (Number) row.get(ManagedConnection.UNACKED_COUNT);
         final Boolean transactional = (Boolean) row.get(ManagedConnection.TRANSACTIONAL);
         final Boolean flowBlocked = (Boolean) row.get(ManagedConnection.FLOW_BLOCKED);
-        assertNotNull("Channel should have unacknowledged messages", unackCount);
-        assertEquals("Unexpected number of unacknowledged messages", 2, unackCount.intValue());
-        assertNotNull("Channel should have transaction flag", transactional);
+        assertEquals("Unexpected number of unacknowledged messages", 2, unackCount);
         assertTrue("Unexpected transaction flag", transactional);
-        assertNotNull("Channel should have flow blocked flag", flowBlocked);
         assertFalse("Unexpected value of flow blocked flag", flowBlocked);
 
+        // check that commit advances the lastIoTime
         final Date initialLastIOTime = mBean.getLastIoTime();
         session.commit();
-        assertTrue("Last IO time should have been updated", mBean.getLastIoTime().after(initialLastIOTime));
-
-        channelsData = mBean.channels();
-        assertNotNull("Channels data are null", channelsData);
-        assertEquals("Unexpected number of rows in channel table", 1, channelsData.size());
-
-        final Iterator<CompositeDataSupport> rowItr2 = (Iterator<CompositeDataSupport>) channelsData.values().iterator();
-        final CompositeDataSupport row2 = rowItr2.next();
-        unackCount = (Number) row2.get(ManagedConnection.UNACKED_COUNT);
-        assertNotNull("Channel should have unacknowledged messages", unackCount);
-        assertEquals("Unexpected number of anacknowledged messages", 0, unackCount.intValue());
+        assertTrue("commit should have caused last IO time to advance", mBean.getLastIoTime().after(initialLastIOTime));
 
-        _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 after connection closed", 0, connections.size());
+        // check that channels() now returns one session with no unacknowledged messages
+        final CompositeDataSupport rowAfterCommit = getTheOneChannelRow(mBean);
+        final Number unackCountAfterCommit = (Number) rowAfterCommit.get(ManagedConnection.UNACKED_COUNT);
+        assertEquals("Unexpected number of unacknowledged messages", 0, unackCountAfterCommit);
     }
 
-    public void testCommit() throws Exception
+    public void testNumberOfManagedConnectionsMatchesNumberOfClientConnections() throws Exception
     {
-        final String queueName = getTestQueueName();
-
-        final Session consumerSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        final Session producerSession = _connection.createSession(true, Session.SESSION_TRANSACTED);
-        final Destination destination = producerSession.createQueue(queueName);
-        final MessageConsumer consumer = consumerSession.createConsumer(destination);
-        final MessageProducer producer = producerSession.createProducer(destination);
-
-        _connection.start();
-
-        List<ManagedConnection> connections = _jmxUtils.getManagedConnections("test");
-        assertNotNull("Connection MBean is not found", connections);
-        assertEquals("Unexpected number of connection mbeans", 1, connections.size());
-        final ManagedConnection mBean = connections.get(0);
-        assertNotNull("Connection MBean is null", mBean);
-
-        final int numberOfMessages = 2;
-        for (int i = 0; i < numberOfMessages; i++)
-        {
-            producer.send(producerSession.createTextMessage("Test " + i));
-        }
+        assertEquals("Expected no managed connections", 0, getManagedConnections().size());
 
-        // sync to make sure that messages are received on the broker
-        // before we commit via JMX
-        ((AMQSession<?, ?>) producerSession).sync();
+        _connection = getConnection();
+        assertEquals("Expected one managed connection", 1, getManagedConnections().size());
 
-        Message m = consumer.receive(500l);
-        assertNull("Unexpected message received", m);
+        _connection.close();
+        assertEquals("Expected no managed connections after client connection closed", 0, getManagedConnections().size());
+    }
 
-        Number channelId = getFirstTransactedChannelId(mBean, 2);
-        mBean.commitTransactions(channelId.intValue());
+    public void testGetAttributes() throws Exception
+    {
+        _connection = getConnection();
+        final ManagedConnection mBean = getConnectionMBean();
 
-        for (int i = 0; i < numberOfMessages; i++)
-        {
-            m = consumer.receive(1000l);
-            assertNotNull("Message " + i + " is not received", m);
-            assertEquals("Unexpected message received at " + i, "Test " + i, ((TextMessage) m).getText());
-        }
-        producerSession.commit();
-        m = consumer.receive(500l);
-        assertNull("Unexpected message received", m);
+        checkAuthorisedId(mBean);
+        checkClientVersion(mBean);
+        checkClientId(mBean);
     }
 
-    protected Number getFirstTransactedChannelId(final ManagedConnection mBean, int channelNumber) throws IOException, JMException
+    private void checkAuthorisedId(ManagedConnection mBean) throws Exception
     {
-        TabularData channelsData = mBean.channels();
-        assertNotNull("Channels data are null", channelsData);
-        assertEquals("Unexpected number of rows in channel table", channelNumber, channelsData.size());
-        final Iterator<CompositeDataSupport> rowItr = (Iterator<CompositeDataSupport>) channelsData.values().iterator();
-        while (rowItr.hasNext())
-        {
-            final CompositeDataSupport row = rowItr.next();
-            Boolean transacted = (Boolean) row.get(ManagedConnection.TRANSACTIONAL);
-            if (transacted.booleanValue())
-            {
-                return (Number) row.get(ManagedConnection.CHAN_ID);
-            }
-        }
-        return null;
+        assertEquals("Unexpected authorized id", GUEST_USERNAME, mBean.getAuthorizedId());
     }
 
-    public void testRollback() throws Exception
+    private void checkClientVersion(ManagedConnection mBean) throws Exception
     {
-        final String queueName = getTestQueueName();
-
-        final Session consumerSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        final Session producerSession = _connection.createSession(true, Session.SESSION_TRANSACTED);
-        final Destination destination = producerSession.createQueue(queueName);
-        final MessageConsumer consumer = consumerSession.createConsumer(destination);
-        final MessageProducer producer = producerSession.createProducer(destination);
-
-        List<ManagedConnection> connections = _jmxUtils.getManagedConnections("test");
-        assertNotNull("Connection MBean is not found", connections);
-        assertEquals("Unexpected number of connection mbeans", 1, connections.size());
-        final ManagedConnection mBean = connections.get(0);
-        assertNotNull("Connection MBean is null", mBean);
-
-        final int numberOfMessages = 2;
-        for (int i = 0; i < numberOfMessages; i++)
-        {
-            producer.send(producerSession.createTextMessage("Test " + i));
-        }
-
-        // sync to make sure that messages are received on the broker
-        // before we rollback via JMX
-        ((AMQSession<?, ?>) producerSession).sync();
-
-        Number channelId = getFirstTransactedChannelId(mBean, 2);
-        mBean.rollbackTransactions(channelId.intValue());
+        String expectedVersion = QpidProperties.getReleaseVersion();
+        assertTrue(StringUtils.isNotBlank(expectedVersion));
 
-        Message m = consumer.receive(1000l);
-        assertNull("Unexpected message received: " + String.valueOf(m), m);
+        assertEquals("Unexpected version", expectedVersion, mBean.getVersion());
+    }
 
-        producerSession.commit();
+    private void checkClientId(ManagedConnection mBean) throws Exception
+    {
+        String expectedClientId = _connection.getClientID();
+        assertTrue(StringUtils.isNotBlank(expectedClientId));
 
-        _connection.start();
-        m = consumer.receive(1000l);
-        assertNull("Unexpected message received after commit " + String.valueOf(m), m);
+        assertEquals("Unexpected ClientId", expectedClientId, mBean.getClientId());
     }
 
-    public void testAuthorisedId() throws Exception
+    private ManagedConnection getConnectionMBean()
     {
-        List<ManagedConnection> connections = _jmxUtils.getManagedConnections("test");
+        List<ManagedConnection> connections = getManagedConnections();
         assertNotNull("Connection MBean is not found", connections);
         assertEquals("Unexpected number of connection mbeans", 1, connections.size());
         final ManagedConnection mBean = connections.get(0);
         assertNotNull("Connection MBean is null", mBean);
-        assertEquals("Unexpected authorized id", "guest", mBean.getAuthorizedId());
+        return mBean;
     }
 
-    public void testClientVersion() throws Exception
+    private CompositeDataSupport getTheOneChannelRow(final ManagedConnection mBean) throws IOException, JMException
     {
-        List<ManagedConnection> connections = _jmxUtils.getManagedConnections("test");
-        assertNotNull("Connection MBean is not found", connections);
-        assertEquals("Unexpected number of connection mbeans", 1, connections.size());
-        final ManagedConnection mBean = connections.get(0);
-        assertNotNull("Connection MBean is null", mBean);
-
-        String expectedVersion = QpidProperties.getReleaseVersion();
-        assertNotNull("version should not be null", expectedVersion);
-        assertFalse("version should not be the empty string", expectedVersion.equals(""));
-        assertFalse("version should not be the string 'null'", expectedVersion.equals("null"));
+        TabularData channelsData = mBean.channels();
+        assertEquals("Unexpected number of rows in channel table", 1, channelsData.size());
 
-        assertEquals("Unexpected version", expectedVersion, mBean.getVersion());
+        @SuppressWarnings("unchecked")
+        final Iterator<CompositeDataSupport> rowItr = (Iterator<CompositeDataSupport>) channelsData.values().iterator();
+        final CompositeDataSupport row = rowItr.next();
+        return row;
     }
 
-    public void testClientId() throws Exception
+    private void receiveTwoMessagesWithoutCommit(final Session session) throws JMSException, Exception
     {
-        List<ManagedConnection> connections = _jmxUtils.getManagedConnections("test");
-        assertNotNull("Connection MBean is not found", connections);
-        assertEquals("Unexpected number of connection mbeans", 1, connections.size());
-        final ManagedConnection mBean = connections.get(0);
-        assertNotNull("Connection MBean is null", mBean);
+        final Destination destination = session.createQueue(getTestQueueName());
+        final MessageConsumer consumer = session.createConsumer(destination);
 
-        String expectedClientId = _connection.getClientID();
-        assertNotNull("ClientId should not be null", expectedClientId);
-        assertFalse("ClientId should not be the empty string", expectedClientId.equals(""));
-        assertFalse("ClientId should not be the string 'null'", expectedClientId.equals("null"));
+        // send two messages ...
+        final int numberOfMessages = 2;
+        sendMessage(session, destination, numberOfMessages);
+        _connection.start();
 
-        assertEquals("Unexpected ClientId", expectedClientId, mBean.getClientId());
+        // receive both messages but don't commit
+        for (int i = 0; i < numberOfMessages; i++)
+        {
+            final Message m = consumer.receive(1000l);
+            assertNotNull("Message " + i + " is not received", m);
+        }
+    }
+
+    private List<ManagedConnection> getManagedConnections()
+    {
+        return _jmxUtils.getManagedConnections(VIRTUAL_HOST_NAME);
     }
+
 }

Modified: qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java (original)
+++ qpid/branches/java-config-and-management/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java Thu Jun  7 10:51:19 2012
@@ -81,6 +81,10 @@ public class QpidBrokerTestCase extends 
         INTERNAL /** Test case starts an embedded broker within this JVM */, 
         SPAWNED /** Test case spawns a new broker as a separate process */
     }
+
+    public static final String GUEST_USERNAME = "guest";
+    public static final String GUEST_PASSWORD = "guest";
+
     protected final static String QpidHome = System.getProperty("QPID_HOME");
     protected File _configFile = new File(System.getProperty("broker.config"));
 
@@ -1029,7 +1033,7 @@ public class QpidBrokerTestCase extends 
     
     public Connection getConnection() throws JMSException, NamingException
     {
-        return getConnection("guest", "guest");
+        return getConnection(GUEST_USERNAME, GUEST_PASSWORD);
     }
 
     public Connection getConnection(ConnectionURL url) throws JMSException

Modified: qpid/branches/java-config-and-management/qpid/java/test-profiles/Excludes
URL: http://svn.apache.org/viewvc/qpid/branches/java-config-and-management/qpid/java/test-profiles/Excludes?rev=1347565&r1=1347564&r2=1347565&view=diff
==============================================================================
--- qpid/branches/java-config-and-management/qpid/java/test-profiles/Excludes (original)
+++ qpid/branches/java-config-and-management/qpid/java/test-profiles/Excludes Thu Jun  7 10:51:19 2012
@@ -41,8 +41,6 @@ org.apache.qpid.systest.disttest.endtoen
 
 //Temp Excludes for branch
 org.apache.qpid.management.jmx.ManagementActorLoggingTest#*
-org.apache.qpid.management.jmx.ManagedConnectionMBeanTest#testCommit
-org.apache.qpid.management.jmx.ManagedConnectionMBeanTest#testRollback
 # Expects management log messages in SystemOut that arent present anymore due to move to plugin
 org.apache.qpid.server.logging.ManagementLoggingTest#*
 #Need to implement a new way to instantiate the BDBHA MBean



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