activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject git commit: Fix for https://issues.apache.org/jira/browse/AMQ-4719
Date Tue, 12 Nov 2013 14:33:33 GMT
Updated Branches:
  refs/heads/trunk 4f1754bdc -> 497fbfc04


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


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

Branch: refs/heads/trunk
Commit: 497fbfc04b1fd8ab1db6afe72742a0755842a73d
Parents: 4f1754b
Author: Rob Davies <rajdavies@gmail.com>
Authored: Tue Nov 12 14:04:06 2013 +0000
Committer: Rob Davies <rajdavies@gmail.com>
Committed: Tue Nov 12 14:05:47 2013 +0000

----------------------------------------------------------------------
 .../activemq/broker/region/RegionBroker.java    | 19 ++--
 .../activemq/broker/LinkStealingTest.java       | 91 ++++++++++++++++++++
 2 files changed, 100 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/497fbfc0/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
b/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
index 108670a..40f599b 100755
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/RegionBroker.java
@@ -33,14 +33,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.jms.InvalidClientIDException;
 import javax.jms.JMSException;
 
-import org.apache.activemq.broker.Broker;
-import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.broker.Connection;
-import org.apache.activemq.broker.ConnectionContext;
-import org.apache.activemq.broker.ConsumerBrokerExchange;
-import org.apache.activemq.broker.EmptyBroker;
-import org.apache.activemq.broker.ProducerBrokerExchange;
-import org.apache.activemq.broker.TransportConnector;
+import org.apache.activemq.broker.*;
 import org.apache.activemq.broker.region.policy.DeadLetterStrategy;
 import org.apache.activemq.broker.region.policy.PolicyMap;
 import org.apache.activemq.command.ActiveMQDestination;
@@ -234,8 +227,14 @@ public class RegionBroker extends EmptyBroker {
                 if (context.isAllowLinkStealing()){
                      clientIdSet.remove(clientId);
                      if (oldContext.getConnection() != null) {
-                        LOG.warn("Stealing link for clientId {} From Connection {}", clientId,
oldContext.getConnection());
-                        oldContext.getConnection().stop();
+                         Connection connection = oldContext.getConnection();
+                         LOG.warn("Stealing link for clientId {} From Connection {}", clientId,
oldContext.getConnection());
+                         if (connection instanceof TransportConnection){
+                            TransportConnection transportConnection = (TransportConnection)
connection;
+                             transportConnection.stopAsync();
+                         }else{
+                             connection.stop();
+                         }
                      }else{
                          LOG.error("Not Connection for {}", oldContext);
                      }

http://git-wip-us.apache.org/repos/asf/activemq/blob/497fbfc0/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
b/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
new file mode 100644
index 0000000..ec944fb
--- /dev/null
+++ b/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
@@ -0,0 +1,91 @@
+/**
+ * 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.broker;
+
+import junit.framework.TestCase;
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+import javax.jms.Connection;
+import javax.jms.InvalidClientIDException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class LinkStealingTest extends TestCase {
+    protected BrokerService brokerService;
+    protected int timeOutInSeconds = 10;
+
+
+    @Override
+    protected void setUp() throws Exception {
+        brokerService = new BrokerService();
+        brokerService.setPersistent(false);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (brokerService != null) {
+            brokerService.stop();
+        }
+    }
+
+
+    public void testStealLinkFails() throws Exception {
+
+        brokerService.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
+        brokerService.start();
+
+        final String clientID = "ThisIsAClientId";
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
+        Connection connection1 = factory.createConnection();
+        connection1.setClientID(clientID);
+        connection1.start();
+
+        AtomicBoolean exceptionFlag = new AtomicBoolean();
+        try {
+            Connection connection2 = factory.createConnection();
+            connection2.setClientID(clientID);
+            connection2.start();
+        } catch (InvalidClientIDException e) {
+            exceptionFlag.set(true);
+        }
+        assertTrue(exceptionFlag.get());
+
+    }
+
+    public void testStealLinkSuccess() throws Exception {
+
+        brokerService.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL+"?allowLinkStealing=true");
+        brokerService.start();
+
+        final String clientID = "ThisIsAClientId";
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
+        Connection connection1 = factory.createConnection();
+        connection1.setClientID(clientID);
+        connection1.start();
+
+        AtomicBoolean exceptionFlag = new AtomicBoolean();
+        try {
+            Connection connection2 = factory.createConnection();
+            connection2.setClientID(clientID);
+            connection2.start();
+        } catch (InvalidClientIDException e) {
+            e.printStackTrace();
+            exceptionFlag.set(true);
+        }
+        assertFalse(exceptionFlag.get());
+
+    }
+}


Mime
View raw message