diff options
author | Martin Ritchie <ritchiem@apache.org> | 2009-12-07 15:17:18 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2009-12-07 15:17:18 +0000 |
commit | 6d10c80d842d8f9558dad15db0ab5a0632aaf578 (patch) | |
tree | 26793fde82678a2962f7fdd9e789fcb573122c29 | |
parent | 45c6056648e86b609b8611cf4be786f430fb31ad (diff) | |
download | qpid-python-6d10c80d842d8f9558dad15db0ab5a0632aaf578.tar.gz |
QPID-2242 : Fixed 0-10 code path's getJMSDestination() updated JMSDestinationTest to cover more test cases:
- Recieving a msg via Queue,Topic
- Recieving a msg via Queue with a MessageListener
- Recieving a msg on a queue that was sent to a topic, requires JMX interface to perform message move.
Excluded test from 0-8 profile until the problem has been resolved
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@887948 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 245 insertions, 90 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java index 667785c441..bea43cc232 100644 --- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java +++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java @@ -784,11 +784,11 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa break; } + } void postDeliver(AbstractJMSMessage msg) throws JMSException { - msg.setJMSDestination(_destination); switch (_acknowledgeMode) { diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java index 338aefbd4a..ffd6e2a13c 100644 --- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java @@ -171,6 +171,11 @@ public class AMQMessageDelegate_0_10 implements AMQMessageDelegate _deliveryTag = deliveryTag; _readableProperties = (_messageProps != null); + AMQDestination dest; + + dest = generateDestination(new AMQShortString(_deliveryProps.getExchange()), + new AMQShortString(_deliveryProps.getRoutingKey())); + setJMSDestination(dest); } diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java new file mode 100644 index 0000000000..6fc6e22267 --- /dev/null +++ b/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java @@ -0,0 +1,237 @@ +/* + * + * 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.test.client.message; + +import org.apache.qpid.client.AMQTopic; +import org.apache.qpid.management.common.mbeans.ManagedQueue; +import org.apache.qpid.test.utils.JMXTestUtils; +import org.apache.qpid.test.utils.QpidTestCase; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.Topic; +import javax.jms.MessageListener; +import javax.management.openmbean.CompositeDataSupport; +import javax.management.openmbean.TabularData; +import java.util.Iterator; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * From the API Docs getJMSDestination: + * + * When a message is received, its JMSDestination value must be equivalent to + * the value assigned when it was sent. + */ +public class JMSDestinationTest extends QpidTestCase implements MessageListener +{ + + private Connection _connection; + private Session _session; + private JMXTestUtils _jmxUtils; + + private static final String USER = "admin"; + private CountDownLatch _receiveMessage; + private Message _message; + + public void setUp() throws Exception + { + _jmxUtils = new JMXTestUtils(this, USER, USER); + _jmxUtils.setUp(); + super.setUp(); + + // Open the JMX Connection + _jmxUtils.open(); + + _connection = getConnection(); + + _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + public void tearDown() throws Exception + { + _jmxUtils.close(); + + super.tearDown(); + } + + /** + * Test a message sent to a queue comes back with JMSDestination queue + * + * @throws Exception + */ + public void testQueue() throws Exception + { + + Queue queue = _session.createQueue(getTestQueueName()); + + MessageConsumer consumer = _session.createConsumer(queue); + + sendMessage(_session, queue, 1); + + _connection.start(); + + Message message = consumer.receive(10000); + + assertNotNull("Message should not be null", message); + + Destination destination = message.getJMSDestination(); + + assertNotNull("JMSDestination should not be null", destination); + + assertEquals("Incorrect Destination type", queue.getClass(), destination.getClass()); + } + + /** + * Test a message sent to a topic comes back with JMSDestination topic + * + * @throws Exception + */ + public void testTopic() throws Exception + { + + Topic topic = _session.createTopic(getTestQueueName() + "Topic"); + + MessageConsumer consumer = _session.createConsumer(topic); + + sendMessage(_session, topic, 1); + + _connection.start(); + + Message message = consumer.receive(10000); + + assertNotNull("Message should not be null", message); + + Destination destination = message.getJMSDestination(); + + assertNotNull("JMSDestination should not be null", destination); + + assertEquals("Incorrect Destination type", topic.getClass(), destination.getClass()); + } + + /** + * Test a message sent to a topic then moved on the broker + * comes back with JMSDestination queue. + * + * i.e. The client is not just setting the value to be the same as the + * current consumer destination. + * + * This test can only be run against the Java broker as it uses JMX to move + * messages between queues. + * + * @throws Exception + */ + public void testMovedToQueue() throws Exception + { + + Queue queue = _session.createQueue(getTestQueueName()); + + _session.createConsumer(queue).close(); + + sendMessage(_session, queue, 1); + + Topic topic = _session.createTopic(getTestQueueName() + "Topic"); + + MessageConsumer consumer = _session.createConsumer(topic); + + // Use Management to move message. + + ManagedQueue managedQueue = _jmxUtils. + getManagedObject(ManagedQueue.class, + _jmxUtils.getQueueObjectName(getConnectionFactory().getVirtualPath().substring(1), + getTestQueueName())); + + // Find the first message on the queue + TabularData data = managedQueue.viewMessages(1L, 2L); + + Iterator values = data.values().iterator(); + assertTrue("No Messages found via JMX", values.hasNext()); + + // Get its message ID + Long msgID = (Long) ((CompositeDataSupport) values.next()).get("AMQ MessageId"); + + // Start the connection and consume message that has been moved to the + // queue + _connection.start(); + + Message message = consumer.receive(1000); + + //Validate we don't have a message on the queue before we start + assertNull("Message should be null", message); + + // Move it to from the topic to the queue + managedQueue.moveMessages(msgID, msgID, ((AMQTopic) topic).getQueueName()); + + // Retrieve the newly moved message + message = consumer.receive(1000); + + assertNotNull("Message should not be null", message); + + Destination destination = message.getJMSDestination(); + + assertNotNull("JMSDestination should not be null", destination); + + assertEquals("Incorrect Destination type", queue.getClass(), destination.getClass()); + } + + /** + * Test a message sent to a queue comes back with JMSDestination queue + * when received via a message listener + * + * @throws Exception + */ + public void testQueueAsync() throws Exception + { + + Queue queue = _session.createQueue(getTestQueueName()); + + MessageConsumer consumer = _session.createConsumer(queue); + + sendMessage(_session, queue, 1); + + _connection.start(); + + _message = null; + _receiveMessage = new CountDownLatch(1); + + consumer.setMessageListener(this); + + assertTrue("Timed out waiting for message to be received ",_receiveMessage.await(1, TimeUnit.SECONDS)); + + assertNotNull("Message should not be null", _message); + + Destination destination = _message.getJMSDestination(); + + assertNotNull("JMSDestination should not be null", destination); + + assertEquals("Incorrect Destination type", queue.getClass(), destination.getClass()); + } + + public void onMessage(Message message) + { + _message = message; + _receiveMessage.countDown(); + } +} diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java deleted file mode 100644 index b30e3c1c1c..0000000000 --- a/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSDestinationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * 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.test.unit.message; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQSession; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.test.utils.QpidTestCase; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jms.Connection; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -/** - * @author Apache Software Foundation - */ -public class JMSDestinationTest extends QpidTestCase -{ - private static final Logger _logger = LoggerFactory.getLogger(JMSDestinationTest.class); - - - protected void setUp() throws Exception - { - super.setUp(); - } - - protected void tearDown() throws Exception - { - super.tearDown(); - } - - public void testJMSDestination() throws Exception - { - AMQConnection con = (AMQConnection) getConnection("guest", "guest"); - AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - Queue queue = - new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("someQ"), new AMQShortString("someQ"), false, - true); - MessageConsumer consumer = consumerSession.createConsumer(queue); - - Connection con2 = (AMQConnection) getConnection("guest", "guest"); - Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); - MessageProducer producer = producerSession.createProducer(queue); - - TextMessage sentMsg = producerSession.createTextMessage("hello"); - assertNull(sentMsg.getJMSDestination()); - - producer.send(sentMsg); - - assertEquals(sentMsg.getJMSDestination(), queue); - - con2.close(); - - con.start(); - - TextMessage rm = (TextMessage) consumer.receive(); - assertNotNull(rm); - - assertEquals(rm.getJMSDestination(), queue); - con.close(); - } - -} diff --git a/java/test-profiles/08Excludes b/java/test-profiles/08Excludes index 6f3898384d..bed6b91da0 100644 --- a/java/test-profiles/08Excludes +++ b/java/test-profiles/08Excludes @@ -18,3 +18,5 @@ org.apache.qpid.client.SessionCreateTest#* org.apache.qpid.management.jmx.ManagementActorLoggingTest#* org.apache.qpid.server.queue.ModelTest#* +// QPID-2242 exclude till issue has been resolved +org.apache.qpid.test.client.message.JMSDestinationTest#* |