You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/06/13 01:06:59 UTC

svn commit: r1349582 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/ActiveMQConnection.java test/java/org/apache/activemq/bugs/AMQ3879Test.java

Author: tabish
Date: Tue Jun 12 23:06:59 2012
New Revision: 1349582

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

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3879Test.java   (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java?rev=1349582&r1=1349581&r2=1349582&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java Tue Jun 12 23:06:59 2012
@@ -24,7 +24,13 @@ import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.concurrent.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -652,14 +658,10 @@ public class ActiveMQConnection implemen
                     // As TemporaryQueue and TemporaryTopic instances are bound
                     // to a connection we should just delete them after the connection
                     // is closed to free up memory
-                    for (Iterator<ActiveMQTempDestination> i = this.activeTempDestinations.values().iterator(); i.hasNext();) {
-                        ActiveMQTempDestination c = i.next();
-                        c.delete();
-                    }
+                    cleanUpTempDestinations();
 
                     if (isConnectionInfoSentToBroker) {
-                        // If we announced ourselfs to the broker.. Try to let
-                        // the broker
+                        // If we announced ourselves to the broker.. Try to let the broker
                         // know that the connection is being shutdown.
                         RemoveInfo removeCommand = info.createRemoveCommand();
                         removeCommand.setLastDeliveredSequenceId(lastDeliveredSequenceId);

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3879Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3879Test.java?rev=1349582&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3879Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3879Test.java Tue Jun 12 23:06:59 2012
@@ -0,0 +1,112 @@
+/**
+ * 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.bugs;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.advisory.AdvisorySupport;
+import org.apache.activemq.broker.BrokerService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AMQ3879Test {
+
+    static final Logger LOG = LoggerFactory.getLogger(AMQ3841Test.class);
+    private BrokerService broker;
+
+    private ActiveMQConnectionFactory factory;
+
+    @Before
+    public void setUp() throws Exception {
+        broker = createBroker();
+        broker.start();
+        broker.waitUntilStarted();
+
+        factory = new ActiveMQConnectionFactory("vm://localhost");
+        factory.setAlwaysSyncSend(true);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        broker.stop();
+        broker.waitUntilStopped();
+        broker = null;
+    }
+
+    protected BrokerService createBroker() throws Exception {
+        BrokerService broker = new BrokerService();
+        broker.setDeleteAllMessagesOnStartup(true);
+        broker.setPersistent(false);
+        broker.setUseJmx(false);
+        broker.setBrokerName("localhost");
+        broker.addConnector("vm://localhost");
+        return broker;
+    }
+
+    @Test
+    public void testConnectionDletesWrongTempDests() throws Exception {
+
+        final Connection connection1 = factory.createConnection();
+        final Connection connection2 = factory.createConnection();
+
+        Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        Destination tempDestAdvisory = AdvisorySupport.TEMP_QUEUE_ADVISORY_TOPIC;
+
+        MessageConsumer advisoryConsumer = session1.createConsumer(tempDestAdvisory);
+        connection1.start();
+
+        Destination tempQueue = session2.createTemporaryQueue();
+        MessageProducer tempProducer = session2.createProducer(tempQueue);
+
+        assertNotNull(advisoryConsumer.receive(5000));
+
+        Thread t = new Thread(new Runnable() {
+
+            @Override
+            public void run() {
+                try {
+                    Thread.sleep(20);
+                    connection1.close();
+                } catch (Exception e) {
+                }
+            }
+        });
+
+        t.start();
+
+        for (int i = 0; i < 256; ++i) {
+            Message msg = session2.createTextMessage("Temp Data");
+            tempProducer.send(msg);
+            Thread.sleep(2);
+        }
+
+        t.join();
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3879Test.java
------------------------------------------------------------------------------
    svn:eol-style = native