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/08/26 23:25:08 UTC

svn commit: r1377521 - in /qpid/trunk/qpid/java: client/src/main/java/org/apache/qpid/client/ common/src/main/java/org/apache/qpid/configuration/ systests/src/main/java/org/apache/qpid/test/unit/client/ systests/src/main/java/org/apache/qpid/test/utils/

Author: robbie
Date: Sun Aug 26 21:25:08 2012
New Revision: 1377521

URL: http://svn.apache.org/viewvc?rev=1377521&view=rev
Log:
QPID-4250: ensure producer creation on 0-8/0-9/0-9-1 connections respects the qpid.declare_exchanges system property. Add systest to highlight the issue and verify the fix. Add constants for the system properties.

Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java?rev=1377521&r1=1377520&r2=1377521&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java Sun Aug 26 21:25:08 2012
@@ -136,10 +136,10 @@ public abstract class AMQSession<C exten
                                                                   DEFAULT_FLOW_CONTROL_WAIT_FAILURE);
 
     private final boolean _delareQueues =
-        Boolean.parseBoolean(System.getProperty("qpid.declare_queues", "true"));
+        Boolean.parseBoolean(System.getProperty(ClientProperties.QPID_DECLARE_QUEUES_PROP_NAME, "true"));
 
     private final boolean _declareExchanges =
-        Boolean.parseBoolean(System.getProperty("qpid.declare_exchanges", "true"));
+        Boolean.parseBoolean(System.getProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "true"));
 
     private final boolean _useAMQPEncodedMapMessage;
 

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java?rev=1377521&r1=1377520&r2=1377521&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java Sun Aug 26 21:25:08 2012
@@ -55,9 +55,10 @@ public class BasicMessageProducer_0_8 ex
 
     void declareDestination(AMQDestination destination)
     {
-
-        final MethodRegistry methodRegistry = getSession().getMethodRegistry();
-        ExchangeDeclareBody body =
+        if(getSession().isDeclareExchanges())
+        {
+            final MethodRegistry methodRegistry = getSession().getMethodRegistry();
+            ExchangeDeclareBody body =
                 methodRegistry.createExchangeDeclareBody(getSession().getTicket(),
                                                          destination.getExchangeName(),
                                                          destination.getExchangeClass(),
@@ -67,12 +68,10 @@ public class BasicMessageProducer_0_8 ex
                                                          false,
                                                          true,
                                                          null);
-        // Declare the exchange
-        // Note that the durable and internal arguments are ignored since passive is set to false
+            AMQFrame declare = body.generateFrame(getChannelId());
 
-        AMQFrame declare = body.generateFrame(getChannelId());
-
-        getProtocolHandler().writeFrame(declare);
+            getProtocolHandler().writeFrame(declare);
+        }
     }
 
     void sendMessage(AMQDestination destination, Message origMessage, AbstractJMSMessage message,

Modified: qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java?rev=1377521&r1=1377520&r2=1377521&view=diff
==============================================================================
--- qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java (original)
+++ qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java Sun Aug 26 21:25:08 2012
@@ -190,6 +190,18 @@ public class ClientProperties
      */
     public static final long DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD = 5000L;
 
+    /**
+     * System property to control whether the client will declare queues during
+     * consumer creation when using BindingURLs.
+     */
+    public static final String QPID_DECLARE_QUEUES_PROP_NAME = "qpid.declare_queues";
+
+    /**
+     * System property to control whether the client will declare exchanges during
+     * producer/consumer creation when using BindingURLs.
+     */
+    public static final String QPID_DECLARE_EXCHANGES_PROP_NAME = "qpid.declare_exchanges";
+
 
     private ClientProperties()
     {

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java?rev=1377521&r1=1377520&r2=1377521&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java Sun Aug 26 21:25:08 2012
@@ -21,8 +21,11 @@
 package org.apache.qpid.test.unit.client;
 
 import org.apache.qpid.AMQException;
+import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.test.utils.JMXTestUtils;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.url.BindingURL;
 
 import javax.jms.Connection;
 import javax.jms.JMSException;
@@ -37,9 +40,37 @@ import javax.jms.Session;
  */
 public class DynamicQueueExchangeCreateTest extends QpidBrokerTestCase
 {
-    public void testQueueDeclare() throws Exception
+    private JMXTestUtils _jmxUtils;
+
+    @Override
+    public void setUp() throws Exception
+    {
+        _jmxUtils = new JMXTestUtils(this);
+        _jmxUtils.setUp();
+
+        super.setUp();
+        _jmxUtils.open();
+    }
+
+    @Override
+    public void tearDown() throws Exception
+    {
+        try
+        {
+            if (_jmxUtils != null)
+            {
+                _jmxUtils.close();
+            }
+        }
+        finally
+        {
+            super.tearDown();
+        }
+    }
+
+    public void testQueueNotDeclaredDuringConsumerCreation() throws Exception
     {
-        setSystemProperty("qpid.declare_queues", "false");
+        setSystemProperty(ClientProperties.QPID_DECLARE_QUEUES_PROP_NAME, "false");
 
         Connection connection = getConnection();
 
@@ -58,16 +89,16 @@ public class DynamicQueueExchangeCreateT
         }
     }
 
-    public void testExchangeDeclare() throws Exception
+    public void testExchangeNotDeclaredDuringConsumerCreation() throws Exception
     {
-        setSystemProperty("qpid.declare_exchanges", "false");
+        setSystemProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "false");
 
         Connection connection = getConnection();
 
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
-        String EXCHANGE_TYPE = "test.direct";
-        Queue queue = session.createQueue("direct://" + EXCHANGE_TYPE + "/queue/queue");
+        String exchangeName = getTestQueueName();
+        Queue queue = session.createQueue("direct://" + exchangeName + "/queue/queue");
 
         try
         {
@@ -78,6 +109,50 @@ public class DynamicQueueExchangeCreateT
         {
             checkExceptionErrorCode(e, AMQConstant.NOT_FOUND);
         }
+
+        //verify the exchange was not declared
+        String exchangeObjectName = _jmxUtils.getExchangeObjectName("test", exchangeName);
+        assertFalse("exchange should not exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName));
+    }
+
+    /**
+     * Checks that setting {@value ClientProperties#QPID_DECLARE_EXCHANGES_PROP_NAME} false results in
+     * disabling implicit ExchangeDeclares during producer creation when using a {@link BindingURL}
+     */
+    public void testExchangeNotDeclaredDuringProducerCreation() throws Exception
+    {
+        Connection connection = getConnection();
+        Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        String exchangeName1 = getTestQueueName() + "1";
+
+
+        Queue queue = session1.createQueue("direct://" + exchangeName1 + "/queue/queue");
+        session1.createProducer(queue);
+
+        //close the session to ensure any previous commands were fully processed by
+        //the broker before observing their effect
+        session1.close();
+
+        //verify the exchange was declared
+        String exchangeObjectName = _jmxUtils.getExchangeObjectName("test", exchangeName1);
+        assertTrue("exchange should exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName));
+
+        //Now disable the implicit exchange declares and try again
+        setSystemProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "false");
+
+        Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        String exchangeName2 = getTestQueueName() + "2";
+
+        Queue queue2 = session2.createQueue("direct://" + exchangeName2 + "/queue/queue");
+        session2.createProducer(queue2);
+
+        //close the session to ensure any previous commands were fully processed by
+        //the broker before observing their effect
+        session2.close();
+
+        //verify the exchange was not declared
+        String exchangeObjectName2 = _jmxUtils.getExchangeObjectName("test", exchangeName2);
+        assertFalse("exchange should not exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName2));
     }
 
     private void checkExceptionErrorCode(JMSException original, AMQConstant code)

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java?rev=1377521&r1=1377520&r2=1377521&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java Sun Aug 26 21:25:08 2012
@@ -303,31 +303,13 @@ public class JMXTestUtils
     }
 
     /**
-     * Retrive the ObjectName for the given Exchange on a VirtualHost.
-     *
-     * This is then used to create a proxy to the ManagedExchange MBean.
-     *
-     * @param virtualHostName the VirtualHost the Exchange is on
-     * @param exchange the Exchange to retireve e.g. 'direct'
-     * @return the ObjectName for the given Exchange on the VirtualHost
+     * Generate the ObjectName for the given Exchange on a VirtualHost.
      */
-    @SuppressWarnings("static-access")
-    public ObjectName getExchangeObjectName(String virtualHostName, String exchange)
+    public String getExchangeObjectName(String virtualHostName, String exchange)
     {
-        // Get the name of the test manager
-        String query = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
+        return "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
                        + ObjectName.quote(virtualHostName) + ",name="
                        + ObjectName.quote(exchange) + ",*";
-
-        Set<ObjectName> objectNames = queryObjects(query);
-
-        _test.assertNotNull("Null ObjectName Set returned", objectNames);
-        _test.assertEquals("Incorrect number of exchange with name '" + exchange + "' returned", 1, objectNames.size());
-
-        // We have verified we have only one value in objectNames so return it
-        ObjectName objectName = objectNames.iterator().next();
-        _test.getLogger().info("Loading: " + objectName);
-        return objectName;
     }
 
     @SuppressWarnings("static-access")
@@ -343,7 +325,7 @@ public class JMXTestUtils
         return getManagedObject(managedClass, objectName);
     }
 
-    public boolean isManagedObjectExist(String query)
+    public boolean doesManagedObjectExist(String query)
     {
         return !queryObjects(query).isEmpty();
     }
@@ -373,9 +355,20 @@ public class JMXTestUtils
         return getManagedObject(ManagedBroker.class, getVirtualHostManagerObjectName(virtualHost));
     }
 
+    @SuppressWarnings("static-access")
     public ManagedExchange getManagedExchange(String exchangeName)
     {
-        ObjectName objectName = getExchangeObjectName("test", exchangeName);
+        String query = getExchangeObjectName("test", exchangeName);
+
+        Set<ObjectName> objectNames = queryObjects(query);
+
+        _test.assertNotNull("Null ObjectName Set returned", objectNames);
+        _test.assertEquals("Incorrect number of exchange with name '" + exchangeName + "' returned", 1, objectNames.size());
+
+        // We have verified we have only one value in objectNames so return an mbean proxy for it
+        ObjectName objectName = objectNames.iterator().next();
+        _test.getLogger().info("Loading: " + objectName);
+
         return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, ManagedExchange.class, false);
     }
 



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