You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2016/05/04 21:18:22 UTC

activemq git commit: Fix race in test due to async processing of the SecurityException, start might throw but the connection doesn't fire the exception listener until afterwards which is what triggers the pool to close the connection.

Repository: activemq
Updated Branches:
  refs/heads/master 1c4108545 -> e3a68717f


Fix race in test due to async processing of the SecurityException, start
might throw but the connection doesn't fire the exception listener until
afterwards which is what triggers the pool to close the connection.

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

Branch: refs/heads/master
Commit: e3a68717f152f90c1cbd4616ff06589c4cf03b4a
Parents: 1c41085
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed May 4 17:14:44 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed May 4 17:15:13 2016 -0400

----------------------------------------------------------------------
 .../PooledConnectionSecurityExceptionTest.java  | 23 +++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/e3a68717/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionSecurityExceptionTest.java
----------------------------------------------------------------------
diff --git a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionSecurityExceptionTest.java b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionSecurityExceptionTest.java
index a9a8bf3..377c210 100644
--- a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionSecurityExceptionTest.java
+++ b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionSecurityExceptionTest.java
@@ -17,6 +17,7 @@
 package org.apache.activemq.jms.pool;
 
 import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
@@ -40,6 +41,7 @@ import org.apache.activemq.security.AuthorizationPlugin;
 import org.apache.activemq.security.DefaultAuthorizationMap;
 import org.apache.activemq.security.SimpleAuthenticationPlugin;
 import org.apache.activemq.security.TempDestinationAuthorizationEntry;
+import org.apache.activemq.util.Wait;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -175,7 +177,7 @@ public class PooledConnectionSecurityExceptionTest {
     }
 
     @Test
-    public void testFailoverWithInvalidCredentials() throws JMSException {
+    public void testFailoverWithInvalidCredentials() throws Exception {
 
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(
             "failover:(" + connectionURI + ")");
@@ -184,24 +186,35 @@ public class PooledConnectionSecurityExceptionTest {
         pooledConnFact.setConnectionFactory(cf);
         pooledConnFact.setMaxConnections(1);
 
-        Connection connection1 = pooledConnFact.createConnection("invalid", "credentials");
+        final Connection connection1 = pooledConnFact.createConnection("invalid", "credentials");
 
         try {
             connection1.start();
             fail("Should fail to connect");
         } catch (JMSSecurityException ex) {
             LOG.info("Caught expected security error");
+            // Intentionally don't close here to see that async pool reconnect takes place.
         }
 
-        Connection connection2 = pooledConnFact.createConnection("invalid", "credentials");
+        // The pool should process the async error
+        assertTrue("Should get new connection", Wait.waitFor(new Wait.Condition() {
+
+            @Override
+            public boolean isSatisified() throws Exception {
+                return connection1 != pooledConnFact.createConnection("invalid", "credentials");
+            }
+        }));
+
+        final Connection connection2 = pooledConnFact.createConnection("invalid", "credentials");
+        assertNotSame(connection1, connection2);
+
         try {
             connection2.start();
             fail("Should fail to connect");
         } catch (JMSSecurityException ex) {
             LOG.info("Caught expected security error");
+            connection2.close();
         }
-
-        assertNotSame(connection1, connection2);
     }
 
     @Test