You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by mi...@apache.org on 2019/01/28 13:30:23 UTC

[activemq-artemis] branch master updated (bcd2f1c -> 4ca3a97)

This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git.


    from bcd2f1c  This closes #2519
     new 0f90522  ARTEMIS-2238 Enhancement to queueQuery on producer
     new 33f56c8  ARTEMIS-2238 Enhancement to queueQuery on producer
     new e595b7c  ARTEMIS-2238 Enhancement to queueQuery on producer
     new 4ca3a97  This closes #2520

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../jms/client/ActiveMQMessageProducer.java        |  53 ++-------
 .../artemis/jms/client/ActiveMQSession.java        |  68 +++++++++---
 .../client/AutoCreateJmsDestinationTest.java       | 121 +++++++++++++++++++++
 3 files changed, 180 insertions(+), 62 deletions(-)


[activemq-artemis] 04/04: This closes #2520

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 4ca3a971baeb97623384ddc17893f7ebaf8cace1
Merge: bcd2f1c e595b7c
Author: Michael Andre Pearce <mi...@me.com>
AuthorDate: Mon Jan 28 13:30:22 2019 +0000

    This closes #2520

 .../jms/client/ActiveMQMessageProducer.java        |  53 ++-------
 .../artemis/jms/client/ActiveMQSession.java        |  68 +++++++++---
 .../client/AutoCreateJmsDestinationTest.java       | 121 +++++++++++++++++++++
 3 files changed, 180 insertions(+), 62 deletions(-)


[activemq-artemis] 02/04: ARTEMIS-2238 Enhancement to queueQuery on producer

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 33f56c81bdefa3492f722a67b5282b527545886c
Author: Michael André Pearce <mi...@me.com>
AuthorDate: Fri Jan 25 01:05:13 2019 +0000

    ARTEMIS-2238 Enhancement to queueQuery on producer
    
    Move logic to ActiveMQSession
    Use same method for createProducer, avoiding duplicated logic
    Specific exception messages, for users
---
 .../jms/client/ActiveMQMessageProducer.java        | 72 ++--------------------
 .../artemis/jms/client/ActiveMQSession.java        | 68 ++++++++++++++------
 2 files changed, 55 insertions(+), 85 deletions(-)

diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
index a813724..e1d71f3 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
@@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.ActiveMQInterruptedException;
-import org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.client.ClientMessage;
 import org.apache.activemq.artemis.api.core.client.ClientProducer;
@@ -396,19 +395,17 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
          if (defaultDestination == null) {
             throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
          }
-
          destination = defaultDestination;
-      } else {
-         if (defaultDestination != null) {
-            if (!destination.equals(defaultDestination)) {
-               throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
-            }
+      } else if (defaultDestination != null) {
+         if (!destination.equals(defaultDestination)) {
+            throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
          }
+      } else {
+         session.checkDestination(destination);
 
          address = destination.getSimpleAddress();
       }
 
-      checkDestination(destination, address, clientSession);
 
       ActiveMQMessage activeMQJmsMessage;
 
@@ -499,66 +496,7 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
       }
    }
 
-   private void checkDestination(ActiveMQDestination destination,
-                                 SimpleString address,
-                                 ClientSession clientSession) throws JMSException {
-
-      // TODO: What to do with FQQN
-      if (!connection.containsKnownDestination(address)) {
-         try {
-            ClientSession.AddressQuery addressQuery = clientSession.addressQuery(address);
-
-            boolean addressExists = addressQuery.isExists();
-            // first we check the address existence, and autoCreate it if allowed in case it does not exists
-
-            if (!addressExists && addressQuery.isAutoCreateAddresses()) {
-
-               if (destination.isQueue() && !addressQuery.isAutoCreateQueues()) {
-                  if (logger.isDebugEnabled()) {
-                     logger.debug("Address " + address + " was not created because we would not have permission to create queue");
-                  }
-                  // if it can't create the internal queue on JMS Queues, why bother creating the address, just mark it false now
-                  addressExists = false;
-               } else {
-                  RoutingType addressType = destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST;
-                  clientSession.createAddress(address, addressType, true);
-                  addressExists = true;
-               }
-            }
-
-
-            // Second we create the queue, but we only do it if the address was created
-            if (destination.isQueue() && addressExists) {
-               ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
-               if (!queueQuery.isExists()) {
-                  if (addressQuery.isAutoCreateQueues()) {
-                     try {
-                        if (destination.isTemporary()) {
-                           session.createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, addressQuery);
-                        } else {
-                           session.createQueue(destination, RoutingType.ANYCAST, address, null, true, true, addressQuery);
-                        }
-                     } catch (ActiveMQQueueExistsException thatsOK) {
-                        // nothing to be done
-                     }
-                  } else {
-                     throw new InvalidDestinationException("Queue " + address + " does not exist");
-                  }
-               }
-            }
-
-            if (!addressExists) {
-               throw new InvalidDestinationException("Address " + address + " does not exist");
-            }
-
 
-            // this is done at the end, if no exceptions are thrown
-            connection.addKnownDestination(address);
-         } catch (ActiveMQException e) {
-            throw JMSExceptionHelper.convertFromActiveMQException(e);
-         }
-      }
-   }
 
    private void checkClosed() throws JMSException {
       if (clientProducer.isClosed()) {
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 c18662b..d8f5079 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
@@ -369,24 +369,7 @@ public class ActiveMQSession implements QueueSession, TopicSession {
          ActiveMQDestination jbd = (ActiveMQDestination) destination;
 
          if (jbd != null) {
-            ClientSession.AddressQuery response = session.addressQuery(jbd.getSimpleAddress());
-
-            if (!response.isExists()) {
-               try {
-                  if (jbd.isQueue() && response.isAutoCreateQueues()) {
-                     // perhaps just relying on the broker to do it is simplest (i.e. purgeOnNoConsumers)
-                     session.createAddress(jbd.getSimpleAddress(), RoutingType.ANYCAST, true);
-                     createQueue(jbd, RoutingType.ANYCAST, jbd.getSimpleAddress(), null, true, true, response);
-                  } else if (!jbd.isQueue() && response.isAutoCreateAddresses()) {
-                     session.createAddress(jbd.getSimpleAddress(), RoutingType.MULTICAST, true);
-                  } else {
-                     throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
-                  }
-               } catch (ActiveMQQueueExistsException e) {
-                  // Queue was created between our query and create queue request.  Ignore.
-               }
-
-            }
+            checkDestination(jbd);
          }
 
          ClientProducer producer = session.createProducer(jbd == null ? null : jbd.getSimpleAddress());
@@ -397,6 +380,55 @@ public class ActiveMQSession implements QueueSession, TopicSession {
       }
    }
 
+   void checkDestination(ActiveMQDestination destination) throws JMSException {
+      SimpleString address = destination.getSimpleAddress();
+      // TODO: What to do with FQQN
+      if (!connection.containsKnownDestination(address)) {
+         try {
+            ClientSession.AddressQuery addressQuery = session.addressQuery(address);
+
+            // First we create the address
+            if (!addressQuery.isExists()) {
+               if (destination.isQueue()) {
+                  if (addressQuery.isAutoCreateAddresses() && addressQuery.isAutoCreateQueues()) {
+                     session.createAddress(address, RoutingType.ANYCAST, true);
+                  } else {
+                     throw new InvalidDestinationException("Destination " + address + " does not exist, autoCreateAddresses=" + addressQuery.isAutoCreateAddresses() + " , autoCreateQueues=" + addressQuery.isAutoCreateQueues());
+                  }
+               } else {
+                  if (addressQuery.isAutoCreateAddresses()) {
+                     session.createAddress(address, RoutingType.MULTICAST, true);
+                  } else {
+                     throw new InvalidDestinationException("Destination " + address + " does not exist, autoCreateAddresses=" + addressQuery.isAutoCreateAddresses());
+                  }
+               }
+            }
+
+            // Second we create the queue, the address would have existed or successfully created.
+            if (destination.isQueue()) {
+               ClientSession.QueueQuery queueQuery = session.queueQuery(address);
+               if (!queueQuery.isExists()) {
+                  if (addressQuery.isAutoCreateQueues()) {
+                     if (destination.isTemporary()) {
+                        createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, addressQuery);
+                     } else {
+                        createQueue(destination, RoutingType.ANYCAST, address, null, true, true, addressQuery);
+                     }
+                  } else {
+                     throw new InvalidDestinationException("Destination " + address + " does not exist, address exists but autoCreateQueues=" + addressQuery.isAutoCreateQueues());
+                  }
+               }
+            }
+         } catch (ActiveMQQueueExistsException thatsOK) {
+            // nothing to be done
+         } catch (ActiveMQException e) {
+            throw JMSExceptionHelper.convertFromActiveMQException(e);
+         }
+         // this is done at the end, if no exceptions are thrown
+         connection.addKnownDestination(address);
+      }
+   }
+
    @Override
    public MessageConsumer createConsumer(final Destination destination) throws JMSException {
       return createConsumer(destination, null, false);


[activemq-artemis] 03/04: ARTEMIS-2238 Enhancement to queueQuery on producer

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit e595b7ca169c0eaa3c5ebd10d102e4252685d201
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri Jan 25 13:27:53 2019 -0500

    ARTEMIS-2238 Enhancement to queueQuery on producer
    
    this is an adjustment on top of 33f56c81bdefa3492f722a67b5282b527545886c
---
 .../artemis/jms/client/ActiveMQMessageProducer.java        | 14 +++++++-------
 .../integration/client/AutoCreateJmsDestinationTest.java   |  3 +--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
index e1d71f3..ccc5d7c 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
@@ -395,18 +395,20 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
          if (defaultDestination == null) {
             throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
          }
+
          destination = defaultDestination;
-      } else if (defaultDestination != null) {
-         if (!destination.equals(defaultDestination)) {
+         // address is meant to be null on this case, as it will use the coreProducer's default address
+      } else {
+         if (defaultDestination != null && !destination.equals(defaultDestination)) {
+            // This is a JMS TCK & Rule Definition.
+            // if you specified a destination on the Producer, you cannot use it for a different destinations.
             throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
          }
-      } else {
-         session.checkDestination(destination);
 
+         session.checkDestination(destination);
          address = destination.getSimpleAddress();
       }
 
-
       ActiveMQMessage activeMQJmsMessage;
 
       boolean foreign = false;
@@ -496,8 +498,6 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
       }
    }
 
-
-
    private void checkClosed() throws JMSException {
       if (clientProducer.isClosed()) {
          throw new IllegalStateException("Producer is closed");
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java
index a7a7a87..f32c6fe 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java
@@ -27,7 +27,6 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.Topic;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
@@ -363,7 +362,7 @@ public class AutoCreateJmsDestinationTest extends JMSTestBase {
       server.getAddressSettingsRepository().addMatch("#", settings);
 
       ConnectionFactory factory = cf;
-      try(Connection connection = factory.createConnection()) {
+      try (Connection connection = factory.createConnection()) {
          SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
          clientSession.createAddress(addressName, RoutingType.ANYCAST, true); // this will force the system to create the address only
          javax.jms.Queue queue = new ActiveMQQueue(addressName.toString());


[activemq-artemis] 01/04: ARTEMIS-2238 Enhancement to queueQuery on producer

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 0f905224e7cd9f71729ebd8434cdde44e396fd0c
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Thu Jan 24 16:01:21 2019 -0500

    ARTEMIS-2238 Enhancement to queueQuery on producer
---
 .../jms/client/ActiveMQMessageProducer.java        | 105 +++++++++++-------
 .../client/AutoCreateJmsDestinationTest.java       | 122 +++++++++++++++++++++
 2 files changed, 188 insertions(+), 39 deletions(-)

diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
index b6c72a7..a813724 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
@@ -47,12 +47,15 @@ import org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler;
 import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.utils.UUID;
 import org.apache.activemq.artemis.utils.UUIDGenerator;
+import org.jboss.logging.Logger;
 
 /**
  * ActiveMQ Artemis implementation of a JMS MessageProducer.
  */
 public class ActiveMQMessageProducer implements MessageProducer, QueueSender, TopicPublisher {
 
+   private static final Logger logger = Logger.getLogger(ActiveMQMessageProducer.class);
+
    private final ConnectionFactoryOptions options;
 
    private final ActiveMQConnection connection;
@@ -403,47 +406,10 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
          }
 
          address = destination.getSimpleAddress();
-
-         if (!connection.containsKnownDestination(address)) {
-            try {
-               ClientSession.AddressQuery query = clientSession.addressQuery(address);
-
-               if (!query.isExists()) {
-                  if (destination.isQueue() && query.isAutoCreateQueues()) {
-                     clientSession.createAddress(address, RoutingType.ANYCAST, true);
-                     if (destination.isTemporary()) {
-                        // TODO is it right to use the address for the queue name here?
-                        session.createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, query);
-                     } else {
-                        session.createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query);
-                     }
-                  } else if (!destination.isQueue() && query.isAutoCreateAddresses()) {
-                     clientSession.createAddress(address, RoutingType.MULTICAST, true);
-                  } else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
-                     throw new InvalidDestinationException("Destination " + address + " does not exist");
-                  }
-               } else {
-                  if (destination.isQueue()) {
-                     ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
-                     if (!queueQuery.isExists()) {
-                        if (destination.isTemporary()) {
-                           session.createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, query);
-                        } else {
-                           session.createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query);
-                        }
-                     }
-                  }
-
-                  connection.addKnownDestination(address);
-               }
-            } catch (ActiveMQQueueExistsException e) {
-               // The queue was created by another client/admin between the query check and send create queue packet
-            } catch (ActiveMQException e) {
-               throw JMSExceptionHelper.convertFromActiveMQException(e);
-            }
-         }
       }
 
+      checkDestination(destination, address, clientSession);
+
       ActiveMQMessage activeMQJmsMessage;
 
       boolean foreign = false;
@@ -533,6 +499,67 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
       }
    }
 
+   private void checkDestination(ActiveMQDestination destination,
+                                 SimpleString address,
+                                 ClientSession clientSession) throws JMSException {
+
+      // TODO: What to do with FQQN
+      if (!connection.containsKnownDestination(address)) {
+         try {
+            ClientSession.AddressQuery addressQuery = clientSession.addressQuery(address);
+
+            boolean addressExists = addressQuery.isExists();
+            // first we check the address existence, and autoCreate it if allowed in case it does not exists
+
+            if (!addressExists && addressQuery.isAutoCreateAddresses()) {
+
+               if (destination.isQueue() && !addressQuery.isAutoCreateQueues()) {
+                  if (logger.isDebugEnabled()) {
+                     logger.debug("Address " + address + " was not created because we would not have permission to create queue");
+                  }
+                  // if it can't create the internal queue on JMS Queues, why bother creating the address, just mark it false now
+                  addressExists = false;
+               } else {
+                  RoutingType addressType = destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST;
+                  clientSession.createAddress(address, addressType, true);
+                  addressExists = true;
+               }
+            }
+
+
+            // Second we create the queue, but we only do it if the address was created
+            if (destination.isQueue() && addressExists) {
+               ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
+               if (!queueQuery.isExists()) {
+                  if (addressQuery.isAutoCreateQueues()) {
+                     try {
+                        if (destination.isTemporary()) {
+                           session.createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, addressQuery);
+                        } else {
+                           session.createQueue(destination, RoutingType.ANYCAST, address, null, true, true, addressQuery);
+                        }
+                     } catch (ActiveMQQueueExistsException thatsOK) {
+                        // nothing to be done
+                     }
+                  } else {
+                     throw new InvalidDestinationException("Queue " + address + " does not exist");
+                  }
+               }
+            }
+
+            if (!addressExists) {
+               throw new InvalidDestinationException("Address " + address + " does not exist");
+            }
+
+
+            // this is done at the end, if no exceptions are thrown
+            connection.addKnownDestination(address);
+         } catch (ActiveMQException e) {
+            throw JMSExceptionHelper.convertFromActiveMQException(e);
+         }
+      }
+   }
+
    private void checkClosed() throws JMSException {
       if (clientProducer.isClosed()) {
          throw new IllegalStateException("Producer is closed");
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java
index 3094c59..a7a7a87 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoCreateJmsDestinationTest.java
@@ -17,26 +17,42 @@
 package org.apache.activemq.artemis.tests.integration.client;
 
 import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
 import javax.jms.JMSSecurityException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+import javax.jms.Topic;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.client.ClientSession;
+import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
+import org.apache.activemq.artemis.api.core.client.ServerLocator;
 import org.apache.activemq.artemis.api.core.management.ResourceNames;
 import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
 import org.apache.activemq.artemis.core.security.Role;
 import org.apache.activemq.artemis.core.server.Queue;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
 import org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic;
+import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
 import org.apache.activemq.artemis.junit.Wait;
 import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
 import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
 import org.apache.activemq.artemis.tests.util.JMSTestBase;
+import org.apache.activemq.artemis.utils.UUIDGenerator;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -48,6 +64,9 @@ public class AutoCreateJmsDestinationTest extends JMSTestBase {
 
    public static final String QUEUE_NAME = "test";
 
+   ClientSessionFactory factory;
+   ClientSession clientSession;
+
    @Test
    public void testAutoCreateOnSendToQueue() throws Exception {
       Connection connection = cf.createConnection();
@@ -265,6 +284,98 @@ public class AutoCreateJmsDestinationTest extends JMSTestBase {
       connection.close();
    }
 
+
+   @Test //(timeout = 30000)
+   // QueueAutoCreationTest was created to validate auto-creation of queues
+   // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238
+   public void testAutoCreateOnTopic() throws Exception {
+      ConnectionFactory factory = new ActiveMQConnectionFactory();
+      Connection connection = factory.createConnection();
+      SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
+      System.out.println("Address is " + addressName);
+      clientSession.createAddress(addressName, RoutingType.ANYCAST, false);
+      Topic topic = new ActiveMQTopic(addressName.toString());
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer producer = session.createProducer(topic);
+      for (int i = 0; i < 10; i++) {
+         producer.send(session.createTextMessage("hello"));
+      }
+
+      Assert.assertTrue(((ActiveMQConnection)connection).containsKnownDestination(addressName));
+   }
+
+   @Test (timeout = 30000)
+   // QueueAutoCreationTest was created to validate auto-creation of queues
+   // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238
+   public void testAutoCreateOnAddressOnly() throws Exception {
+
+      server.getAddressSettingsRepository().clear();
+      AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(false);
+      server.getAddressSettingsRepository().addMatch("#", settings);
+
+      ConnectionFactory factory = new ActiveMQConnectionFactory();
+      try (Connection connection = factory.createConnection()) {
+         SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
+         System.out.println("Address is " + addressName);
+         javax.jms.Queue queue = new ActiveMQQueue(addressName.toString());
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer producer = session.createProducer(null);
+         try {
+            producer.send(queue, session.createTextMessage("hello"));
+            Assert.fail("Expected to throw exception here");
+         } catch (JMSException expected) {
+         }
+         Assert.assertFalse(((ActiveMQConnection)connection).containsKnownDestination(addressName));
+      }
+
+   }
+
+   @Test (timeout = 30000)
+   // QueueAutoCreationTest was created to validate auto-creation of queues
+   // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238
+   public void testAutoCreateOnAddressOnlyDuringProducerCreate() throws Exception {
+      server.getAddressSettingsRepository().clear();
+      AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(false);
+      server.getAddressSettingsRepository().addMatch("#", settings);
+
+      ConnectionFactory factory = new ActiveMQConnectionFactory();
+      Connection connection = factory.createConnection();
+      SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
+      clientSession.createAddress(addressName, RoutingType.ANYCAST, true); // this will force the system to create the address only
+      javax.jms.Queue queue = new ActiveMQQueue(addressName.toString());
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      try {
+         MessageProducer producer = session.createProducer(queue);
+         Assert.fail("Exception expected");
+      } catch (JMSException expected) {
+      }
+
+      Assert.assertFalse(((ActiveMQConnection)connection).containsKnownDestination(addressName));
+   }
+
+
+   @Test (timeout = 30000)
+   // QueueAutoCreationTest was created to validate auto-creation of queues
+   // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238
+   public void testAutoCreateOnAddressOnlyDuringProducerCreateQueueSucceed() throws Exception {
+      server.getAddressSettingsRepository().clear();
+      AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(true);
+      server.getAddressSettingsRepository().addMatch("#", settings);
+
+      ConnectionFactory factory = cf;
+      try(Connection connection = factory.createConnection()) {
+         SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
+         clientSession.createAddress(addressName, RoutingType.ANYCAST, true); // this will force the system to create the address only
+         javax.jms.Queue queue = new ActiveMQQueue(addressName.toString());
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer producer = session.createProducer(queue);
+         Assert.assertNotNull(server.locateQueue(addressName));
+
+         Assert.assertTrue(((ActiveMQConnection) connection).containsKnownDestination(addressName));
+      }
+   }
+
+
    @Before
    @Override
    public void setUp() throws Exception {
@@ -276,6 +387,17 @@ public class AutoCreateJmsDestinationTest extends JMSTestBase {
       Set<Role> roles = new HashSet<>();
       roles.add(role);
       server.getSecurityRepository().addMatch("#", roles);
+      ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
+      factory = locator.createSessionFactory();
+      clientSession = factory.createSession();
+   }
+
+   @After
+   @Override
+   public void tearDown() throws Exception {
+      clientSession.close();
+      factory.close();
+      super.tearDown();
    }
 
    @Override