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/09/03 10:14:55 UTC

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

Author: kwall
Date: Wed Sep  3 08:14:55 2014
New Revision: 1622176

URL: http://svn.apache.org/r1622176
Log:
QPID-6066: [Java Client]  0-8..0-9-1 only - Add system property to allow call to exchange.bound during AMQSession#getQueueDepth to be omitted

This prevents interoperabiliy problem with older Java Brokers, and gives users a change to restore old behaviour (AMQChannelException in the event
that the queue does not exist) if desired.

Modified:
    qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
    qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
    qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java
    qpid/trunk/qpid/java/test-profiles/Java010Excludes

Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java?rev=1622176&r1=1622175&r2=1622176&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java Wed Sep  3 08:14:55 2014
@@ -58,6 +58,7 @@ import org.apache.qpid.client.state.AMQS
 import org.apache.qpid.client.state.AMQStateManager;
 import org.apache.qpid.client.state.listener.SpecificMethodFrameListener;
 import org.apache.qpid.common.AMQPFilterTypes;
+import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.framing.*;
 import org.apache.qpid.framing.amqp_0_9.MethodRegistry_0_9;
 import org.apache.qpid.framing.amqp_0_91.MethodRegistry_0_91;
@@ -77,6 +78,9 @@ public class AMQSession_0_8 extends AMQS
     private final boolean _syncAfterClientAck =
             Boolean.parseBoolean(System.getProperty(QPID_SYNC_AFTER_CLIENT_ACK, "true"));
 
+    private final boolean _useLegacyQueueDepthBehaviour =
+            Boolean.parseBoolean(System.getProperty(ClientProperties.QPID_USE_LEGACY_GETQUEUEDEPTH_BEHAVIOUR, "false"));
+
     /**
      * The period to wait while flow controlled before sending a log message confirming that the session is still
      * waiting on flow control being revoked
@@ -878,7 +882,8 @@ public class AMQSession_0_8 extends AMQS
 
     protected Long requestQueueDepth(AMQDestination amqd, boolean sync) throws AMQException, FailoverException
     {
-        if(isBound(null, amqd.getAMQQueueName(), null))
+
+        if(_useLegacyQueueDepthBehaviour || isBound(null, amqd.getAMQQueueName(), null))
         {
             AMQFrame queueDeclare =
                     getMethodRegistry().createQueueDeclareBody(getTicket(),

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=1622176&r1=1622175&r2=1622176&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 Wed Sep  3 08:14:55 2014
@@ -270,6 +270,16 @@ public class ClientProperties
     public static final String ADDR_SYNTAX_SUPPORTED_IN_0_8 = "qpid.addr_syntax_supported";
     public static final boolean DEFAULT_ADDR_SYNTAX_0_8_SUPPORT = true;
 
+    /**
+     * Before 0.30, when using AMQP 0-8..0-9-1 requesting queue depth (AMQSession#getQueueDepth) for a queue that
+     * did not exist resulted in AMQChannelException.  From 0.30 forward, 0 is returned in common with 0-10
+     * behaviour.
+     *
+     * Setting this system property true restores the old behaviour.  It also avoids the isBound with a null exchange
+     * that causes an error in the Java Broker (0.28 and earlier).
+     */
+    public static final String QPID_USE_LEGACY_GETQUEUEDEPTH_BEHAVIOUR = "qpid.use_legacy_getqueuedepth_behavior";
+
     private ClientProperties()
     {
         //No instances

Modified: qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java?rev=1622176&r1=1622175&r2=1622176&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java Wed Sep  3 08:14:55 2014
@@ -20,19 +20,23 @@
  */
 package org.apache.qpid.test.unit.client;
 
+import org.apache.qpid.AMQChannelClosedException;
+import org.apache.qpid.AMQException;
 import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQSession_0_8;
 import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.protocol.AMQConstant;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
 
 import javax.jms.JMSException;
 import javax.jms.QueueReceiver;
 import javax.jms.TopicSubscriber;
 
-/**
- * Tests for QueueReceiver and TopicSubscriber creation methods on AMQSession
- */
+
 public class AMQSessionTest extends QpidBrokerTestCase
 {
 
@@ -44,23 +48,10 @@ public class AMQSessionTest extends Qpid
     protected void setUp() throws Exception
     {
         super.setUp();
-        _connection = (AMQConnection) getConnection("guest", "guest");
-        _topic = new AMQTopic(_connection,"mytopic");
-        _queue = new AMQQueue(_connection,"myqueue");
-        _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
-    }
-
-    protected void tearDown() throws Exception
-    {
-        try
-        {
-            _connection.close();
-        }
-        catch (JMSException e)
-        {
-            //just close
-        }
-        super.tearDown();
+        _connection = (AMQConnection) getConnection();
+        _topic = new AMQTopic(_connection, "mytopic");
+        _queue = new AMQQueue(_connection, "myqueue");
+        _session = (AMQSession) _connection.createSession(true, AMQSession.SESSION_TRANSACTED);
     }
 
     public void testCreateSubscriber() throws JMSException
@@ -69,7 +60,9 @@ public class AMQSessionTest extends Qpid
         assertEquals("Topic names should match from TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName());
 
         subscriber = _session.createSubscriber(_topic, "abc", false);
-        assertEquals("Topic names should match from TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName());
+        assertEquals("Topic names should match from TopicSubscriber with selector",
+                     _topic.getTopicName(),
+                     subscriber.getTopic().getTopicName());
     }
 
     public void testCreateDurableSubscriber() throws JMSException
@@ -101,4 +94,46 @@ public class AMQSessionTest extends Qpid
         assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName());
     }
 
+    public void testQueueDepthForQueueWithDepth() throws Exception
+    {
+        AMQDestination dest = (AMQDestination) _session.createQueue(getTestQueueName());
+        _session.createConsumer(dest).close();
+
+        long depth = _session.getQueueDepth(dest);
+        assertEquals("Unexpected queue depth for empty queue", 0 , depth);
+
+        sendMessage(_session, dest, 1);
+
+        depth = _session.getQueueDepth(dest);
+        assertEquals("Unexpected queue depth for empty queue", 1, depth);
+    }
+
+    public void testQueueDepthForQueueThatDoesNotExist() throws Exception
+    {
+        AMQDestination dest = (AMQDestination) _session.createQueue(getTestQueueName());
+
+        long depth = _session.getQueueDepth(dest);
+        assertEquals("Unexpected queue depth for non-existent queue", 0 , depth);
+    }
+
+    public void testQueueDepthForQueueThatDoesNotExistLegacyBehaviour_08_091() throws Exception
+    {
+        _session.close();
+
+        setTestClientSystemProperty(ClientProperties.QPID_USE_LEGACY_GETQUEUEDEPTH_BEHAVIOUR, "true");
+        _session = (AMQSession) _connection.createSession(true, AMQSession.SESSION_TRANSACTED);
+
+        AMQDestination dest = (AMQDestination) _session.createQueue(getTestQueueName());
+
+        try
+        {
+            _session.getQueueDepth(dest);
+            fail("Exception not thrown");
+        }
+        catch(AMQChannelClosedException cce)
+        {
+            assertEquals(AMQConstant.NOT_FOUND, cce.getErrorCode());
+        }
+    }
+
 }

Modified: qpid/trunk/qpid/java/test-profiles/Java010Excludes
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/Java010Excludes?rev=1622176&r1=1622175&r2=1622176&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/Java010Excludes (original)
+++ qpid/trunk/qpid/java/test-profiles/Java010Excludes Wed Sep  3 08:14:55 2014
@@ -72,3 +72,5 @@ org.apache.qpid.server.queue.QueueBindTe
 
 // Java 0-10 exclusive queues are owned by sessions not by the client-id, so the owner is not meaningful from JMX
 org.apache.qpid.systest.management.jmx.QueueManagementTest#testExclusiveQueueHasJmsClientIdAsOwner
+
+org.apache.qpid.test.unit.client.AMQSessionTest#testQueueDepthForQueueThatDoesNotExistLegacyBehaviour_08_091



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