diff options
author | Keith Wall <kwall@apache.org> | 2014-09-05 16:04:34 +0000 |
---|---|---|
committer | Keith Wall <kwall@apache.org> | 2014-09-05 16:04:34 +0000 |
commit | b32805028ccffd85a7c6149d32190a449816d851 (patch) | |
tree | 274b9ec9f0861565d613dc2198279cb37c0a7741 | |
parent | aa9a8e6e242054d4a835bde7f6e2a286397ec390 (diff) | |
download | qpid-python-b32805028ccffd85a7c6149d32190a449816d851.tar.gz |
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.
Merged from trunk with command:
svn merge -c 1622176 https://svn.apache.org/repos/asf/qpid/trunk/qpid
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.30@1622730 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 74 insertions, 22 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java index fbf8b27630..2bc614e163 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java @@ -58,6 +58,7 @@ import org.apache.qpid.client.state.AMQState; 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 AMQSession<BasicMessageConsumer_0_8, BasicMe 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 @@ -868,7 +872,8 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe 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(), diff --git a/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java b/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java index a767b078b1..b29e77f14d 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java @@ -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 diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java index 0d81b66be0..d6ec3794d9 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java @@ -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 QpidBrokerTestCase 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 QpidBrokerTestCase 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 QpidBrokerTestCase 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()); + } + } + } diff --git a/qpid/java/test-profiles/Java010Excludes b/qpid/java/test-profiles/Java010Excludes index 46f789c229..8406f6e940 100755 --- a/qpid/java/test-profiles/Java010Excludes +++ b/qpid/java/test-profiles/Java010Excludes @@ -72,3 +72,5 @@ org.apache.qpid.server.queue.QueueBindTest#testQueueCanBeReboundOnTopicExchange // 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 |