You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/06/07 19:04:12 UTC

[2/2] activemq-artemis git commit: ARTEMIS-1206 SetClientID from Core ConnectionFactory is not unique

ARTEMIS-1206 SetClientID from Core ConnectionFactory is not unique


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

Branch: refs/heads/master
Commit: 545414c18b0109f4c0ff4877be3d3e090b7c9586
Parents: 9d5d2d5
Author: Clebert Suconic <cl...@apache.org>
Authored: Tue Jun 6 12:58:28 2017 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Wed Jun 7 15:03:59 2017 -0400

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQConnection.java  | 22 +++++++++-----
 .../integration/jms/client/ConnectionTest.java  | 30 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/545414c1/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnection.java
----------------------------------------------------------------------
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 0ff0a21..6432af2 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
@@ -242,13 +242,7 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme
          throw new IllegalStateException("setClientID can only be called directly after the connection is created");
       }
 
-      try {
-         initialSession.addUniqueMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientID);
-      } catch (ActiveMQException e) {
-         if (e.getType() == ActiveMQExceptionType.DUPLICATE_METADATA) {
-            throw new InvalidClientIDException("clientID=" + clientID + " was already set into another connection");
-         }
-      }
+      validateClientID(initialSession, clientID);
 
       this.clientID = clientID;
       try {
@@ -263,6 +257,16 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme
       justCreated = false;
    }
 
+   private void validateClientID(ClientSession validateSession, String clientID) throws InvalidClientIDException {
+      try {
+         validateSession.addUniqueMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientID);
+      } catch (ActiveMQException e) {
+         if (e.getType() == ActiveMQExceptionType.DUPLICATE_METADATA) {
+            throw new InvalidClientIDException("clientID=" + clientID + " was already set into another connection");
+         }
+      }
+   }
+
    @Override
    public ConnectionMetaData getMetaData() throws JMSException {
       checkClosed();
@@ -669,6 +673,10 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme
       try {
          initialSession = sessionFactory.createSession(username, password, false, false, false, false, 0);
 
+         if (clientID != null) {
+            validateClientID(initialSession, clientID);
+         }
+
          addSessionMetaData(initialSession);
 
          initialSession.addFailureListener(listener);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/545414c1/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/ConnectionTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/ConnectionTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/ConnectionTest.java
index 7770726..8ea65db 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/ConnectionTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/ConnectionTest.java
@@ -100,8 +100,38 @@ public class ConnectionTest extends JMSTestBase {
       } catch (InvalidClientIDException expected) {
          // expected
       }
+
+
+      Session session1 = conn.createSession();
+      Session session2 = conn.createSession();
+
+      session1.close();
+      session2.close();
+
    }
 
+
+   @Test
+   public void testTwoConnectionsSameIDThroughCF() throws Exception {
+      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid");
+
+      conn = connectionFactory.createConnection();
+      try {
+         conn2 = connectionFactory.createConnection();
+         Assert.fail("Exception expected");
+      } catch (InvalidClientIDException expected) {
+         // expected
+      }
+
+
+      Session session1 = conn.createSession();
+      Session session2 = conn.createSession();
+
+      session1.close();
+      session2.close();
+   }
+
+
    @Test
    public void testGetSetConnectionFactory() throws Exception {
       conn = cf.createConnection();