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 7164a2c8ea8..9745cb1ed85 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 @@ -537,6 +537,7 @@ public void addTemporaryQueue(final SimpleString queueAddress) { 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 87912781ef6..af4077a7bbf 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 @@ -27,6 +27,8 @@ import javax.jms.TextMessage; import javax.naming.NamingException; +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; @@ -126,6 +128,51 @@ public void testTemporaryQueueBasic() throws Exception { } } + @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 */