activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1236707 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/ test/java/org/apache/activemq/usecases/ test/resources/org/apache/activemq/usecases/
Date Fri, 27 Jan 2012 15:08:23 GMT
Author: dejanb
Date: Fri Jan 27 15:08:23 2012
New Revision: 1236707

URL: http://svn.apache.org/viewvc?rev=1236707&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3685 - sanitize brokerUrl in BrokerInfo as it can
break failover url when cluster update is used

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ClientRebalanceTest.java
    activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker1.xml
    activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker2.xml
    activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker3.xml
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java?rev=1236707&r1=1236706&r2=1236707&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnector.java
Fri Jan 27 15:08:23 2012
@@ -16,14 +16,6 @@
  */
 package org.apache.activemq.broker;
 
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.regex.Pattern;
-import javax.management.ObjectName;
 import org.apache.activemq.broker.jmx.ManagedTransportConnector;
 import org.apache.activemq.broker.jmx.ManagementContext;
 import org.apache.activemq.broker.region.ConnectorStatistics;
@@ -43,6 +35,15 @@ import org.apache.activemq.util.ServiceS
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.management.ObjectName;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.regex.Pattern;
+
 /**
  * @org.apache.xbean.XBean
  *
@@ -208,7 +209,7 @@ public class TransportConnector implemen
         brokerInfo.setBrokerId(broker.getBrokerId());
         brokerInfo.setPeerBrokerInfos(broker.getPeerBrokerInfos());
         brokerInfo.setFaultTolerantConfiguration(broker.isFaultTolerantConfiguration());
-        brokerInfo.setBrokerURL(getServer().getConnectURI().toString());
+        brokerInfo.setBrokerURL(getPublishableConnectString(getServer().getConnectURI()));
         getServer().setAcceptListener(new TransportAcceptListener() {
             public void onAccept(final Transport transport) {
                 try {
@@ -256,10 +257,13 @@ public class TransportConnector implemen
 
         LOG.info("Connector " + getName() + " Started");
     }
-
+    
     public String getPublishableConnectString() throws Exception {
+        return getPublishableConnectString(getConnectUri());
+    }
+
+    public String getPublishableConnectString(URI theConnectURI) throws Exception {
         String publishableConnectString = null;
-        URI theConnectURI = getConnectUri();
         if (theConnectURI != null) {
             publishableConnectString = theConnectURI.toString();
             // strip off server side query parameters which may not be compatible to

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ClientRebalanceTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ClientRebalanceTest.java?rev=1236707&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ClientRebalanceTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ClientRebalanceTest.java
Fri Jan 27 15:08:23 2012
@@ -0,0 +1,89 @@
+/**
+ * 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.activemq.usecases;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.JmsMultipleBrokersTestSupport;
+import org.apache.log4j.Logger;
+import org.springframework.core.io.ClassPathResource;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+public class ClientRebalanceTest extends JmsMultipleBrokersTestSupport {
+    private static final Logger LOG = Logger.getLogger(ClientRebalanceTest.class);
+    private static final String QUEUE_NAME = "Test.ClientRebalanceTest";
+    
+    public void testRebalance() throws Exception {
+        createBroker(new ClassPathResource("org/apache/activemq/usecases/rebalance-broker1.xml"));
+        createBroker(new ClassPathResource("org/apache/activemq/usecases/rebalance-broker2.xml"));
+
+        startAllBrokers();
+
+        brokers.get("b1").broker.waitUntilStarted();
+
+
+        LOG.info("Starting connection");
+        
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61617)?randomize=false");
+        Connection conn = factory.createConnection();
+        conn.start();
+        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue theQueue = session.createQueue(QUEUE_NAME);
+        MessageProducer producer = session.createProducer(theQueue);
+        MessageConsumer consumer = session.createConsumer(theQueue);
+        Message message = session.createTextMessage("Test message");
+        producer.send(message);
+        Message msg = consumer.receive(2000);
+        assertNotNull(msg);
+
+
+        // introduce third broker
+        createBroker(new ClassPathResource("org/apache/activemq/usecases/rebalance-broker3.xml"));
+        brokers.get("b3").broker.waitUntilStarted();
+        
+        Thread.sleep(1000);
+
+
+        LOG.info("Stopping broker 1");
+
+
+        brokers.get("b1").broker.stop();
+        brokers.get("b1").broker.waitUntilStopped();
+        
+        Thread.sleep(1000);
+        // should reconnect to some of the remaining brokers
+        producer.send(message);
+        msg = consumer.receive(2000);
+        assertNotNull(msg);
+
+        LOG.info("Stopping broker 2");
+
+        brokers.get("b2").broker.stop();
+        brokers.get("b2").broker.waitUntilStopped();
+
+        // should reconnect to broker3
+        producer.send(message);
+        msg = consumer.receive(2000);
+        assertNotNull(msg);
+    }
+    
+}

Added: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker1.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker1.xml?rev=1236707&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker1.xml
(added)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker1.xml
Fri Jan 27 15:08:23 2012
@@ -0,0 +1,13 @@
+<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd"
xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <broker brokerName="b1" persistent="false" useJmx="false" xmlns="http://activemq.apache.org/schema/core">
+        <networkConnectors>
+            <networkConnector name="b1_b2" uri="static://tcp://localhost:61617" duplex="false"/>
+            <networkConnector name="b1_b3" uri="static://tcp://localhost:61618"></networkConnector>
+        </networkConnectors>
+
+        <!-- The transport connectors ActiveMQ will listen to -->
+        <transportConnectors>
+            <transportConnector name="openwire" uri="tcp://localhost:61616?transport.closeAsync=false"
rebalanceClusterClients="true" updateClusterClients="true"/>
+        </transportConnectors>
+    </broker>
+</beans>
\ No newline at end of file

Added: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker2.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker2.xml?rev=1236707&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker2.xml
(added)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker2.xml
Fri Jan 27 15:08:23 2012
@@ -0,0 +1,14 @@
+<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd"
xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+        <broker brokerName="b2" persistent="false" useJmx="false" xmlns="http://activemq.apache.org/schema/core">
+
+        <networkConnectors>
+            <networkConnector name="b2_b1" uri="static://tcp://localhost:61616" duplex="false"/>
+            <networkConnector name="b2_b3" uri="static://tcp://localhost:61618"></networkConnector>
+        </networkConnectors>
+
+        <!-- The transport connectors ActiveMQ will listen to -->
+        <transportConnectors>
+            <transportConnector name="openwire" uri="tcp://localhost:61617?transport.closeAsync=false"
rebalanceClusterClients="true" updateClusterClients="true"/>
+        </transportConnectors>
+    </broker>
+</beans>
\ No newline at end of file

Added: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker3.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker3.xml?rev=1236707&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker3.xml
(added)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/usecases/rebalance-broker3.xml
Fri Jan 27 15:08:23 2012
@@ -0,0 +1,13 @@
+<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd"
xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <broker brokerName="b3" persistent="false" useJmx="true" xmlns="http://activemq.apache.org/schema/core">
+        <networkConnectors>
+            <networkConnector name="b3_b1" uri="static://tcp://localhost:61616"></networkConnector>
+            <networkConnector name="b3_b2" uri="static://tcp://localhost:61617"></networkConnector>
+        </networkConnectors>
+
+        <!-- The transport connectors ActiveMQ will listen to -->
+        <transportConnectors>
+            <transportConnector name="openwire" uri="tcp://localhost:61618?transport.closeAsync=false"
rebalanceClusterClients="true" updateClusterClients="true"/>
+        </transportConnectors>
+    </broker>
+</beans>
\ No newline at end of file



Mime
View raw message