activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject activemq git commit: AMQ-7088 - fix deadlock on remove add interaction from mqtt virtual topic sub use case
Date Thu, 01 Nov 2018 10:11:28 GMT
Repository: activemq
Updated Branches:
  refs/heads/master bf8eb08ac -> f2cde24a6


AMQ-7088 - fix deadlock on remove add interaction from mqtt virtual topic sub use case


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

Branch: refs/heads/master
Commit: f2cde24a62d61fb1015b15d0ce25801353db0621
Parents: bf8eb08
Author: gtully <gary.tully@gmail.com>
Authored: Thu Nov 1 10:11:08 2018 +0000
Committer: gtully <gary.tully@gmail.com>
Committed: Thu Nov 1 10:11:08 2018 +0000

----------------------------------------------------------------------
 .../virtual/VirtualDestinationInterceptor.java  |   4 +-
 .../activemq/broker/virtual/AMQ7088Test.java    | 129 +++++++++++++++++++
 2 files changed, 131 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/f2cde24a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualDestinationInterceptor.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualDestinationInterceptor.java
b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualDestinationInterceptor.java
index d3c5cee..0741cc0 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualDestinationInterceptor.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualDestinationInterceptor.java
@@ -78,14 +78,14 @@ public class VirtualDestinationInterceptor implements DestinationInterceptor
{
     }
 
     @Override
-    public synchronized void create(Broker broker, ConnectionContext context, ActiveMQDestination
destination) throws Exception {
+    public void create(Broker broker, ConnectionContext context, ActiveMQDestination destination)
throws Exception {
         for (VirtualDestination virt : virtualDestinations) {
             virt.create(broker, context, destination);
         }
     }
 
     @Override
-    public synchronized void remove(Destination destination) {
+    public void remove(Destination destination) {
     }
 
     public VirtualDestination[] getVirtualDestinations() {

http://git-wip-us.apache.org/repos/asf/activemq/blob/f2cde24a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ7088Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ7088Test.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ7088Test.java
new file mode 100644
index 0000000..ff810cf
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/virtual/AMQ7088Test.java
@@ -0,0 +1,129 @@
+/**
+ * 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.virtual;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.ActiveMQPrefetchPolicy;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.DestinationInfo;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.Assert.assertTrue;
+
+public class AMQ7088Test {
+
+    private static final Logger LOG = LoggerFactory.getLogger(AMQ7088Test.class);
+
+    BrokerService brokerService;
+    ConnectionFactory connectionFactory;
+
+    @Before
+    public void createBroker() throws Exception {
+        createBroker(true);
+    }
+
+    public void createBroker(boolean delete) throws Exception  {
+        brokerService = new BrokerService();
+        brokerService.setDeleteAllMessagesOnStartup(delete);
+        brokerService.setAdvisorySupport(false);
+        brokerService.addConnector("tcp://localhost:0");
+        brokerService.start();
+
+        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString());
+        ActiveMQPrefetchPolicy zeroPrefetch = new ActiveMQPrefetchPolicy();
+        zeroPrefetch.setAll(0);
+        activeMQConnectionFactory.setPrefetchPolicy(zeroPrefetch);
+        activeMQConnectionFactory.setWatchTopicAdvisories(false);
+        connectionFactory = activeMQConnectionFactory;
+    }
+
+    @After
+    public void stopBroker() throws Exception  {
+        brokerService.stop();
+    }
+
+    @Test
+    public void testDeadlockOnAddRemoveDest() throws Exception {
+
+        final int numConnections = 100;
+        final AtomicInteger numConsumers = new AtomicInteger(numConnections);
+
+        ExecutorService executorService = Executors.newFixedThreadPool(numConnections);
+
+        Runnable runnable = new Runnable() {
+            @Override
+            public void run() {
+
+                try {
+                    do {
+                        int i = numConsumers.decrementAndGet();
+                        if (i >= 0) {
+
+                            Connection connection1 = connectionFactory.createConnection();
+                            connection1.start();
+
+                            Session session = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+
+                            ActiveMQQueue queue = new ActiveMQQueue("Consumer." + i + ".VirtualTopic.TEST.*");
+                            MessageConsumer messageConsumer = session.createConsumer(queue);
+
+                            messageConsumer.close();
+
+                            ActiveMQConnection activeMQConnection = (ActiveMQConnection)
connection1;
+                            DestinationInfo remove = new DestinationInfo();
+                            remove.setConnectionId(activeMQConnection.getConnectionInfo().getConnectionId());
+                            remove.setDestination(queue);
+                            remove.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE);
+
+                            activeMQConnection.getTransport().request(remove);
+
+                            connection1.close();
+                        }
+
+                    } while (numConsumers.get() > 0);
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        };
+
+        for (int i = 0; i < numConnections; i++) {
+            executorService.execute(runnable);
+        }
+
+        LOG.info("Letting it run to completion...");
+        executorService.shutdown();
+        assertTrue("all done", executorService.awaitTermination(5, TimeUnit.MINUTES));
+    }
+}


Mime
View raw message