You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2013/11/14 10:49:02 UTC

[1/2] git commit: Fix for https://issues.apache.org/jira/browse/AMQ-4884

Updated Branches:
  refs/heads/trunk c55a66692 -> 0a67b12c6


Fix for https://issues.apache.org/jira/browse/AMQ-4884


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/291ec5ea
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/291ec5ea
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/291ec5ea

Branch: refs/heads/trunk
Commit: 291ec5ea17817cb374c1a2342dd280ee986ebaa3
Parents: c55a666
Author: rajdavies <ra...@gmail.com>
Authored: Thu Nov 14 09:47:40 2013 +0000
Committer: rajdavies <ra...@gmail.com>
Committed: Thu Nov 14 09:47:40 2013 +0000

----------------------------------------------------------------------
 .../JmsTopicWildcardSendReceiveTest.java        | 26 ++++++++++++++++++++
 .../activemq/filter/DestinationFilterTest.java  | 21 ++++++++++++++++
 2 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/291ec5ea/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTopicWildcardSendReceiveTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTopicWildcardSendReceiveTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTopicWildcardSendReceiveTest.java
index 52cf2be..eeb5999 100755
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTopicWildcardSendReceiveTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsTopicWildcardSendReceiveTest.java
@@ -174,6 +174,32 @@ public class JmsTopicWildcardSendReceiveTest extends JmsTopicSendReceiveTest {
         assertNull(consumer.receiveNoWait());
     }
 
+    public void testReceiveWildcardTopicMatchSinglePastTheEndWildcard() throws Exception {
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        ActiveMQDestination destination1 = (ActiveMQDestination)session.createTopic("a.>");
+        ActiveMQDestination destination2 = (ActiveMQDestination)session.createTopic("a");
+
+        Message m = null;
+        MessageConsumer consumer = null;
+        String text = null;
+
+
+        consumer = session.createConsumer(destination1);
+        sendMessage(session, destination2, destination3String);
+
+        m = consumer.receive(1000);
+        assertNotNull(m);
+        text = ((TextMessage)m).getText();
+        if (!(text.equals(destination1String) || text.equals(destination3String))) {
+            fail("unexpected message:" + text);
+        }
+
+        assertNull(consumer.receiveNoWait());
+    }
+
+
 
     private void sendMessage(Session session, Destination destination, String text) throws JMSException {
         MessageProducer producer = session.createProducer(destination);

http://git-wip-us.apache.org/repos/asf/activemq/blob/291ec5ea/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
index 53ea0e7..95af394 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
@@ -41,4 +41,25 @@ public class DestinationFilterTest extends TestCase {
 		assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof CompositeDestinationFilter);
 		assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B")));
 	}
+
+    public void testMatchesChild() throws Exception{
+        DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.*.C"));
+        assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B.C")));
+
+        filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.*"));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B")));
+        assertFalse("Filter did match", filter.matches(new ActiveMQQueue("A")));
+    }
+
+    public void testMatchesAny() throws Exception{
+        DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.>.>"));
+
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.C")));
+
+        assertFalse("Filter did match", filter.matches(new ActiveMQQueue("B")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B.C.D.E.F")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A")));
+    }
 }


[2/2] git commit: Fix for https://issues.apache.org/jira/browse/AMQ-4884

Posted by ra...@apache.org.
Fix for https://issues.apache.org/jira/browse/AMQ-4884


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/0a67b12c
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/0a67b12c
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/0a67b12c

Branch: refs/heads/trunk
Commit: 0a67b12c647bc3fb42542b640dfb698fcf802456
Parents: 291ec5e
Author: rajdavies <ra...@gmail.com>
Authored: Thu Nov 14 09:48:34 2013 +0000
Committer: rajdavies <ra...@gmail.com>
Committed: Thu Nov 14 09:48:34 2013 +0000

----------------------------------------------------------------------
 .../filter/PrefixDestinationFilter.java         | 22 ++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/0a67b12c/activemq-client/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java b/activemq-client/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
index abe7530..5f9b6bc 100755
--- a/activemq-client/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
+++ b/activemq-client/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
@@ -40,22 +40,40 @@ public class PrefixDestinationFilter extends DestinationFilter {
         this.destinationType = destinationType;
     }
 
+
     public boolean matches(ActiveMQDestination destination) {
-    	if (destination.getDestinationType() != destinationType) return false;
+        if (destination.getDestinationType() != destinationType) return false;
         String[] path = DestinationPath.getDestinationPaths(destination.getPhysicalName());
+
+
         int length = prefixes.length;
         if (path.length >= length) {
             int size = length - 1;
             for (int i = 0; i < size; i++) {
-                if (!path[i].equals(ANY_CHILD) && !prefixes[i].equals(ANY_CHILD) && !prefixes[i].equals(path[i])) {
+                if (!matches(prefixes[i],path[i])) {
                     return false;
                 }
             }
             return true;
+        }else{
+            //want to look for the case where A matches A.>
+            boolean match = true;
+            for (int i = 0; (i < path.length && match); i++){
+                   match &= matches(prefixes[i],path[i]);
+            }
+            //paths get compacted - e.g. A.*.> will be compacted to A.> and by definition - the last element on
+            //the prefix will be >
+            if (match && prefixes.length == (path.length + 1)){
+                return true;
+            }
         }
         return false;
     }
 
+    private boolean matches(String prefix,String path){
+        return path.equals(ANY_CHILD) || prefix.equals(ANY_CHILD) || prefix.equals(path);
+    }
+
     public String getText() {
         return DestinationPath.toString(prefixes);
     }