From a988f9f74a38cbe56251a9cd9b91758198f56fdc Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Tue, 4 Dec 2018 11:01:30 -0600 Subject: [PATCH] ARTEMIS-2190 core JMS client leaks temp dest names --- .../jms/client/ActiveMQConnection.java | 1 + .../jms/tests/TemporaryDestinationTest.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) 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 */