QPID-8141: [JMS AMQP 0-x] Enforce resolution of destinations with unset legacy fields
authorAlex Rudyy <orudyy@apache.org>
Mon, 30 Apr 2018 12:54:59 +0000 (13:54 +0100)
committerAlex Rudyy <orudyy@apache.org>
Mon, 30 Apr 2018 12:54:59 +0000 (13:54 +0100)
client/src/main/java/org/apache/qpid/client/AMQSession.java
systests/src/test/java/org/apache/qpid/systest/destination/AddressBasedDestinationTest.java

index 63cc7a8..cba764e 100644 (file)
@@ -676,7 +676,30 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
 
     boolean isResolved(final AMQDestination dest)
     {
-        return _resolvedDestinations.contains(dest);
+        if (!_resolvedDestinations.contains(dest))
+        {
+            return false;
+        }
+
+        if (dest.getAddressType() == AMQDestination.QUEUE_TYPE)
+        {
+            // verify legacy fields are set
+            return dest.getQueueName() != null
+                   && dest.getQueueName().equals(dest.getAddressName())
+                   && dest.getExchangeName() != null
+                   && dest.getExchangeClass() != null
+                   && dest.getRoutingKey() != null;
+        }
+        else if (dest.getAddressType() == AMQDestination.TOPIC_TYPE)
+        {
+            // verify legacy fields are set
+            return dest.getExchangeName() != null
+                   && dest.getExchangeName().equals(dest.getAddressName())
+                   && dest.getExchangeClass() != null
+                   && (dest.getSubject() == null
+                        || (dest.getSubject() != null && dest.getSubject().equals(dest.getRoutingKey())));
+        }
+        return false;
     }
 
     public abstract int resolveAddressType(AMQDestination dest) throws QpidException;
index cced94d..395b410 100644 (file)
@@ -373,6 +373,54 @@ public class AddressBasedDestinationTest extends JmsTestBase
         }
     }
 
+    @Test
+    public void ensureQueueDestinationAlwaysResolved() throws Exception
+    {
+        String address = String.format("ADDR:%s; {create: always, node: {type: queue}}", getTestName());
+
+        Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+
+        MessageProducer producer = session.createProducer(null);
+        producer.send(session.createQueue(address), session.createTextMessage("A"));
+        producer.send(session.createQueue(address), session.createTextMessage("B"));
+        session.commit();
+
+        MessageConsumer consumer = session.createConsumer(session.createQueue(address));
+        Message messageA = consumer.receive(getReceiveTimeout());
+        assertNotNull("Message A is not received", messageA);
+        assertTrue("Unexpected type of message A", messageA instanceof TextMessage);
+        assertEquals("Unexpected content of message A", "A", ((TextMessage) messageA).getText());
+
+        Message messageB = consumer.receive(getReceiveTimeout());
+        assertNotNull("Message B is not received", messageB);
+        assertTrue("Unexpected type of message B", messageB instanceof TextMessage);
+        assertEquals("Unexpected content of message B", "B", ((TextMessage) messageB).getText());
+    }
+
+
+    @Test
+    public void ensureTopicDestinationAlwaysResolved() throws Exception
+    {
+        String address = String.format("ADDR:amq.topic/%s; {node: {type: topic}}", getTestName());
+        Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+        MessageConsumer consumer = session.createConsumer(session.createTopic(address));
+
+        MessageProducer producer = session.createProducer(null);
+        producer.send(session.createTopic(address), session.createTextMessage("A"));
+        producer.send(session.createTopic(address), session.createTextMessage("B"));
+        session.commit();
+
+        Message messageA = consumer.receive(getReceiveTimeout());
+        assertNotNull("Message A is not received", messageA);
+        assertTrue("Unexpected type of message A", messageA instanceof TextMessage);
+        assertEquals("Unexpected content of message A", "A", ((TextMessage) messageA).getText());
+
+        Message messageB = consumer.receive(getReceiveTimeout());
+        assertNotNull("Message B is not received", messageB);
+        assertTrue("Unexpected type of message B", messageB instanceof TextMessage);
+        assertEquals("Unexpected content of message B", "B", ((TextMessage) messageB).getText());
+    }
+
     private void createExchangeImpl(final boolean withExchangeArgs,
                                     final boolean useNonsenseArguments,
                                     final boolean useNonsenseExchangeType) throws Exception