diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnection.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnection.java index eea238be12..2300a54ad7 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnection.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnection.java @@ -548,6 +548,7 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme public void removeTemporaryQueue(final SimpleString queueAddress) { tempQueues.remove(queueAddress); + knownDestinations.remove(queueAddress); } public void addKnownDestination(final SimpleString address) { diff --git a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/TemporaryDestinationTest.java b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/TemporaryDestinationTest.java index 2a4ad4194f..6b29aea9fe 100644 --- a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/TemporaryDestinationTest.java +++ b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/TemporaryDestinationTest.java @@ -28,6 +28,8 @@ import javax.jms.TextMessage; import javax.naming.NamingException; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.jms.client.ActiveMQConnection; import org.apache.activemq.artemis.jms.tests.util.ProxyAssertSupport; import org.junit.Test; @@ -127,6 +129,51 @@ public class TemporaryDestinationTest extends JMSTestCase { } } + @Test + public void testTemporaryQueueLeak() throws Exception { + ActiveMQConnection conn = null; + + try { + conn = (ActiveMQConnection) createConnection(); + + Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + + Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + + TemporaryQueue tempQueue = producerSession.createTemporaryQueue(); + + MessageProducer producer = producerSession.createProducer(tempQueue); + + MessageConsumer consumer = consumerSession.createConsumer(tempQueue); + + conn.start(); + + final String messageText = "This is a message"; + + Message m = producerSession.createTextMessage(messageText); + + producer.send(m); + + TextMessage m2 = (TextMessage) consumer.receive(2000); + + ProxyAssertSupport.assertNotNull(m2); + + ProxyAssertSupport.assertEquals(messageText, m2.getText()); + + consumer.close(); + + tempQueue.delete(); + + ProxyAssertSupport.assertFalse(conn.containsKnownDestination(SimpleString.toSimpleString(tempQueue.getQueueName()))); + + ProxyAssertSupport.assertFalse(conn.containsTemporaryQueue(SimpleString.toSimpleString(tempQueue.getQueueName()))); + } finally { + if (conn != null) { + conn.close(); + } + } + } + /** * http://jira.jboss.com/jira/browse/JBMESSAGING-93 */