[1/2] activemq-artemis git commit: This closes #2448

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] activemq-artemis git commit: This closes #2448

nigrofranz
Repository: activemq-artemis
Updated Branches:
  refs/heads/master f75da3c85 -> f5b509b96


This closes #2448


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

Branch: refs/heads/master
Commit: f5b509b9620dd5ad714eb4bf41395d62fb65ac95
Parents: f75da3c 8a46c3e
Author: Francesco Nigro <[hidden email]>
Authored: Thu Dec 6 17:03:58 2018 +0100
Committer: Francesco Nigro <[hidden email]>
Committed: Thu Dec 6 17:03:58 2018 +0100

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQDestination.java |  21 ++--
 .../artemis/jms/client/ActiveMQSession.java     |   4 +
 .../jms/tests/TemporaryDestinationTest.java     | 121 +++++++++++++++++++
 3 files changed, 138 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

[2/2] activemq-artemis git commit: ARTEMIS-2189 allow deleting temp dest when session is closed

nigrofranz
ARTEMIS-2189 allow deleting temp dest when session is closed


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

Branch: refs/heads/master
Commit: 8a46c3ee16308fcb8b09df16e5bfdf20173c60f7
Parents: f75da3c
Author: Justin Bertram <[hidden email]>
Authored: Mon Dec 3 13:44:32 2018 -0600
Committer: Francesco Nigro <[hidden email]>
Committed: Thu Dec 6 17:03:58 2018 +0100

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQDestination.java |  21 ++--
 .../artemis/jms/client/ActiveMQSession.java     |   4 +
 .../jms/tests/TemporaryDestinationTest.java     | 121 +++++++++++++++++++
 3 files changed, 138 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8a46c3ee/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
index 6d1b409..54178c0 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
@@ -386,14 +386,19 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
 
    public void delete() throws JMSException {
       if (session != null) {
-         if (session.getCoreSession().isClosed()) {
-            // Temporary queues will be deleted when the connection is closed.. nothing to be done then!
-            return;
-         }
-         if (isQueue()) {
-            session.deleteTemporaryQueue(this);
-         } else {
-            session.deleteTemporaryTopic(this);
+         /**
+          * The status of the session used to create the temporary destination is uncertain, but the JMS spec states
+          * that the lifetime of the temporary destination is tied to the connection so even if the originating
+          * session is closed the temporary destination should still be deleted. Therefore, just create a new one
+          * and close it after the temporary destination is deleted. This is necessary because the Core API is
+          * predicated on having a Core ClientSession which is encapsulated by the JMS session implementation.
+          */
+         try (ActiveMQSession sessionToUse = (ActiveMQSession) session.getConnection().createSession()) {
+            if (isQueue()) {
+               sessionToUse.deleteTemporaryQueue(this);
+            } else {
+               sessionToUse.deleteTemporaryTopic(this);
+            }
          }
       }
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8a46c3ee/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
index 5b75f7f..ae68283 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
@@ -1190,6 +1190,10 @@ public class ActiveMQSession implements QueueSession, TopicSession {
       }
    }
 
+   public ActiveMQConnection getConnection() {
+      return connection;
+   }
+
    // Protected -----------------------------------------------------
 
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/8a46c3ee/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/TemporaryDestinationTest.java
----------------------------------------------------------------------
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 8791278..2a4ad41 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,7 @@ import javax.jms.TemporaryTopic;
 import javax.jms.TextMessage;
 import javax.naming.NamingException;
 
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.jms.tests.util.ProxyAssertSupport;
 import org.junit.Test;
 
@@ -266,6 +267,126 @@ public class TemporaryDestinationTest extends JMSTestCase {
    }
 
    @Test
+   public void testTemporaryQueueDeletedAfterSessionClosed() throws Exception {
+      servers.get(0).getActiveMQServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false));
+
+      Connection conn = null;
+
+      try {
+         conn = createConnection();
+
+         Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Make sure temporary queue cannot be used after it has been deleted
+
+         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();
+
+         consumerSession.close();
+
+         producer.close();
+
+         producerSession.close();
+
+         tempQueue.delete();
+
+         producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         try {
+            producer = producerSession.createProducer(tempQueue);
+            producer.send(m);
+            ProxyAssertSupport.fail();
+         } catch (JMSException e) {
+         }
+      } finally {
+         if (conn != null) {
+            conn.close();
+         }
+      }
+   }
+
+   @Test
+   public void testTemporaryTopicDeletedAfterSessionClosed() throws Exception {
+      servers.get(0).getActiveMQServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false));
+
+      Connection conn = null;
+
+      try {
+         conn = createConnection();
+
+         Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Make sure temporary topic cannot be used after it has been deleted
+
+         TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
+
+         MessageProducer producer = producerSession.createProducer(tempTopic);
+
+         MessageConsumer consumer = consumerSession.createConsumer(tempTopic);
+
+         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();
+
+         consumerSession.close();
+
+         producer.close();
+
+         producerSession.close();
+
+         tempTopic.delete();
+
+         producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         try {
+            producer = producerSession.createProducer(tempTopic);
+            producer.send(m);
+            ProxyAssertSupport.fail();
+         } catch (JMSException e) {
+         }
+      } finally {
+         if (conn != null) {
+            conn.close();
+         }
+      }
+   }
+
+   @Test
    public void testTemporaryTopicBasic() throws Exception {
       Connection conn = null;