activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1240287 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/command/ActiveMQDestination.java test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Date Fri, 03 Feb 2012 18:46:03 GMT
Author: tabish
Date: Fri Feb  3 18:46:03 2012
New Revision: 1240287

URL: http://svn.apache.org/viewvc?rev=1240287&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-3586

Trim whitespace from destination names

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java?rev=1240287&r1=1240286&r2=1240287&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
Fri Feb  3 18:46:03 2012
@@ -42,9 +42,9 @@ import org.apache.activemq.util.URISuppo
 
 /**
  * @openwire:marshaller
- * 
+ *
  */
-public abstract class ActiveMQDestination extends JNDIBaseStorable implements DataStructure,
Destination, Externalizable, Comparable {
+public abstract class ActiveMQDestination extends JNDIBaseStorable implements DataStructure,
Destination, Externalizable, Comparable<Object> {
 
     public static final String PATH_SEPERATOR = ".";
     public static final char COMPOSITE_SEPERATOR = ',';
@@ -73,7 +73,7 @@ public abstract class ActiveMQDestinatio
     protected Map<String, String> options;
 
     protected static UnresolvedDestinationTransformer unresolvableDestinationTransformer
= new DefaultUnresolvedDestinationTransformer();
-    
+
     public ActiveMQDestination() {
     }
 
@@ -121,7 +121,7 @@ public abstract class ActiveMQDestinatio
         if (dest instanceof ActiveMQDestination) {
             return (ActiveMQDestination)dest;
         }
-        
+
         if (dest instanceof Queue && dest instanceof Topic) {
             String queueName = ((Queue) dest).getQueueName();
             String topicName = ((Topic) dest).getTopicName();
@@ -165,6 +165,7 @@ public abstract class ActiveMQDestinatio
         }
     }
 
+    @Override
     public int compareTo(Object that) {
         if (that instanceof ActiveMQDestination) {
             return compare(this, (ActiveMQDestination)that);
@@ -221,6 +222,7 @@ public abstract class ActiveMQDestinatio
     }
 
     public void setPhysicalName(String physicalName) {
+        physicalName = physicalName.trim();
         final int len = physicalName.length();
         // options offset
         int p = -1;

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java?rev=1240287&r1=1240286&r2=1240287&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Fri Feb  3 18:46:03 2012
@@ -334,6 +334,45 @@ public class MBeanTest extends EmbeddedB
         assertEquals("dest has no memory usage", 0, queue.getMemoryPercentUsage());
     }
 
+    public void testCreateDestinationWithSpacesAtEnds() throws Exception {
+        ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Broker,BrokerName=localhost");
+        BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
brokerName, BrokerViewMBean.class, true);
+
+        assertTrue("broker is not a slave", !broker.isSlave());
+        // create 2 topics
+        broker.addTopic(getDestinationString() + "1 ");
+        broker.addTopic(" " + getDestinationString() + "2");
+        broker.addTopic(" " + getDestinationString() + "3 ");
+
+        assertNotRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination="
+ getDestinationString() + "1 ");
+        assertNotRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination=
" + getDestinationString() + "2");
+        assertNotRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination=
" + getDestinationString() + "3 ");
+
+        ObjectName topicObjName1 = assertRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination="
+ getDestinationString() + "1");
+        ObjectName topicObjName2 = assertRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination="
+ getDestinationString() + "2");
+        ObjectName topicObjName3 = assertRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination="
+ getDestinationString() + "3");
+
+        TopicViewMBean topic1 = (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
topicObjName1, TopicViewMBean.class, true);
+        TopicViewMBean topic2 = (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
topicObjName2, TopicViewMBean.class, true);
+        TopicViewMBean topic3 = (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
topicObjName3, TopicViewMBean.class, true);
+
+        assertEquals("topic1 Durable subscriber count", 0, topic1.getConsumerCount());
+        assertEquals("topic2 Durable subscriber count", 0, topic2.getConsumerCount());
+        assertEquals("topic3 Durable subscriber count", 0, topic3.getConsumerCount());
+
+        String topicName = getDestinationString();
+        String selector = null;
+
+        // create 1 subscriber for each topic
+        broker.createDurableSubscriber(clientID, "topic1.subscriber1", topicName + "1", selector);
+        broker.createDurableSubscriber(clientID, "topic2.subscriber1", topicName + "2", selector);
+        broker.createDurableSubscriber(clientID, "topic3.subscriber1", topicName + "3", selector);
+
+        assertEquals("topic1 Durable subscriber count", 1, topic1.getConsumerCount());
+        assertEquals("topic2 Durable subscriber count", 1, topic2.getConsumerCount());
+        assertEquals("topic3 Durable subscriber count", 1, topic3.getConsumerCount());
+    }
+
     @SuppressWarnings("rawtypes")
     protected void assertSendViaMBean() throws Exception {
         String queueName = getDestinationString() + ".SendMBBean";
@@ -415,7 +454,6 @@ public class MBeanTest extends EmbeddedB
         assertEquals("Message " + messageIndex + " CData field: " + name, expected, value);
     }
 
-
     protected void assertQueueBrowseWorks() throws Exception {
         Integer mbeancnt = mbeanServer.getMBeanCount();
         echo("Mbean count :" + mbeancnt);
@@ -630,6 +668,16 @@ public class MBeanTest extends EmbeddedB
         return objectName;
     }
 
+    protected ObjectName assertNotRegisteredObjectName(String name) throws MalformedObjectNameException,
NullPointerException {
+        ObjectName objectName = new ObjectName(name);
+        if (mbeanServer.isRegistered(objectName)) {
+            fail("Found the MBean!: " + objectName);
+        } else {
+            echo("Bean not registered Registered: " + objectName);
+        }
+        return objectName;
+    }
+
     protected void setUp() throws Exception {
         bindAddress = "tcp://localhost:0";
         useTopic = false;



Mime
View raw message