diff options
4 files changed, 95 insertions, 34 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java index 20eaca44ae..308c63923e 100644 --- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java +++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java @@ -590,20 +590,21 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac } - void checkValidQueue() throws JMSException + private void checkValidQueue() throws JMSException { if(_destination instanceof AMQQueue) { - checkValidQueue(_destination); + checkValidQueue((AMQQueue) _destination); } } - void checkValidQueue(AMQDestination destination) throws JMSException + + private void checkValidQueue(AMQQueue destination) throws JMSException { if (!destination.isCheckedForQueueBinding() && validateQueueOnSend()) { if (getSession().isStrictAMQP()) { - getLogger().warn("AMQP does not support destination validation before publish, "); + getLogger().warn("AMQP does not support destination validation before publish"); destination.setCheckedForQueueBinding(true); } else @@ -615,7 +616,7 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac else { throw new InvalidDestinationException("Queue: " + destination.getName() - + " is not a valid destination (no bindings on server"); + + " is not a valid destination (no binding on server)"); } } } diff --git a/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java index 891cb9581c..d309251b44 100644 --- a/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java +++ b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java @@ -20,18 +20,53 @@ */ package org.apache.qpid.client; -import junit.framework.TestCase; - -import org.apache.qpid.AMQInvalidArgumentException; +import java.util.concurrent.atomic.AtomicReference; import javax.jms.ExceptionListener; import javax.jms.JMSException; -import java.util.concurrent.atomic.AtomicReference; -public class AMQConnectionUnitTest extends TestCase +import org.apache.qpid.AMQInvalidArgumentException; +import org.apache.qpid.configuration.ClientProperties; +import org.apache.qpid.jms.ConnectionURL; +import org.apache.qpid.test.utils.QpidTestCase; + +public class AMQConnectionUnitTest extends QpidTestCase { String _url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; + public void testVerifyQueueOnSendDefault() throws Exception + { + MockAMQConnection connection = new MockAMQConnection(_url); + assertFalse(connection.validateQueueOnSend()); + } + + public void testVerifyQueueOnSendViaSystemProperty() throws Exception + { + setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "true"); + MockAMQConnection connection = new MockAMQConnection(_url); + assertTrue(connection.validateQueueOnSend()); + + setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false"); + connection = new MockAMQConnection(_url); + assertFalse(connection.validateQueueOnSend()); + } + + public void testVerifyQueueOnSendViaURL() throws Exception + { + MockAMQConnection connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='true'"); + assertTrue(connection.validateQueueOnSend()); + + connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='false'"); + assertFalse(connection.validateQueueOnSend()); + } + + public void testVerifyQueueOnSendViaURLoverridesSystemProperty() throws Exception + { + setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false"); + MockAMQConnection connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='true'"); + assertTrue(connection.validateQueueOnSend()); + } + public void testExceptionReceived() { AMQInvalidArgumentException expectedException = new AMQInvalidArgumentException("Test", null); @@ -79,4 +114,5 @@ public class AMQConnectionUnitTest extends TestCase MockAMQConnection connection = new MockAMQConnection(_url + "&use_legacy_stream_msg_format='false'"); assertFalse("Stream message encoding should be amqp/list",connection.isUseLegacyStreamMessageFormat()); } + } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java index ac6cad879b..8c193622e3 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java @@ -591,5 +591,36 @@ public class ConnectionURLTest extends TestCase assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL))); } + + /** + * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is not + * specified, asking for the option returns null, such that this can later be used to + * verify it wasn't specified. + */ + public void testDefaultVerifyQueueOnSend() throws URLSyntaxException + { + String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'"; + ConnectionURL connectionURL = new AMQConnectionURL(url); + + assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL)); + } + + /** + * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is + * specified, asking for the option returns the value, such that this can later be used + * to verify what value it was specified as. + */ + public void testOverridingVerifyQueueOnSend() throws URLSyntaxException + { + String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='true'"; + ConnectionURL connectionURL = new AMQConnectionURL(url); + + assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND))); + + url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='false'"; + connectionURL = new AMQConnectionURL(url); + + assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND))); + } } diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java index 05b19c3391..8961574d1e 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java +++ b/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java @@ -55,11 +55,8 @@ public class InvalidDestinationTest extends QpidBrokerTestCase super.tearDown(); } - - public void testInvalidDestination() throws Exception { - QueueSession queueSession = _connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue invalidDestination = queueSession.createQueue("unknownQ"); @@ -98,37 +95,39 @@ public class InvalidDestinationTest extends QpidBrokerTestCase sender.close(); sender = queueSession.createSender(validDestination); sender.send(msg); - - - - } - - + /** + * Tests that specifying the {@value ClientProperties#VERIFY_QUEUE_ON_SEND} system property + * results in an exception when sending to an invalid queue destination. + */ public void testInvalidDestinationOnMessageProducer() throws Exception { setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "true"); final AMQConnection connection = (AMQConnection) getConnection(); doInvalidDestinationOnMessageProducer(connection); - } - + /** + * Tests that specifying the {@value ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND} + * connection URL option property results in an exception when sending to an + * invalid queue destination. + */ public void testInvalidDestinationOnMessageProducerURL() throws Exception { Map<String, String> options = Collections.singletonMap(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND, "true"); doInvalidDestinationOnMessageProducer(getConnectionWithOptions(options)); - } private void doInvalidDestinationOnMessageProducer(Connection connection) throws JMSException { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue invalidDestination = session.createQueue("unknownQ"); + String invalidQueueName = getTestQueueName() + "UnknownQ"; + Queue invalidDestination = session.createQueue(invalidQueueName); - Queue validDestination = session.createQueue("knownQ"); + String validQueueName = getTestQueueName() + "KnownQ"; + Queue validDestination = session.createQueue(validQueueName); // This is the only easy way to create and bind a queue from the API :-( session.createConsumer(validDestination); @@ -146,9 +145,8 @@ public class InvalidDestinationTest extends QpidBrokerTestCase // pass } - sender = session.createProducer(null); - invalidDestination = new AMQQueue("amq.direct","unknownQ"); + invalidDestination = new AMQQueue("amq.direct",invalidQueueName); try { @@ -164,15 +162,10 @@ public class InvalidDestinationTest extends QpidBrokerTestCase sender = session.createProducer(validDestination); sender.send(msg); - Topic topic = session.createTopic("randomTopic"); + //Verify sending to an 'invalid' Topic doesn't throw an exception + String invalidTopic = getTestQueueName() + "UnknownT"; + Topic topic = session.createTopic(invalidTopic); sender = session.createProducer(topic); sender.send(msg); } - - - public static junit.framework.Test suite() - { - - return new junit.framework.TestSuite(InvalidDestinationTest.class); - } } |
