From 2e64abc38a0605f31fc47a89c8313f29cc72c170 Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Wed, 11 May 2016 16:03:19 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6290 Close failed connection on start if the reconnect on exception flag is enabled. --- .../activemq/jms/pool/ConnectionPool.java | 3 +++ .../PooledConnectionSecurityExceptionTest.java | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/ConnectionPool.java b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/ConnectionPool.java index 2be4a6f090..a449f9f8e1 100644 --- a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/ConnectionPool.java +++ b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/ConnectionPool.java @@ -125,6 +125,9 @@ public class ConnectionPool implements ExceptionListener { connection.start(); } catch (JMSException e) { started.set(false); + if (isReconnectOnException()) { + close(); + } throw(e); } } 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 3a8eb27285..a2338edd15 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 @@ -105,8 +105,17 @@ public class PooledConnectionSecurityExceptionTest { LOG.info("Successfully create new connection."); } + @Test + public void testFailureGetsNewConnectionOnRetryLooped() throws Exception { + for (int i = 0; i < 10; ++i) { + testFailureGetsNewConnectionOnRetry(); + } + } + @Test public void testFailureGetsNewConnectionOnRetry() throws Exception { + pooledConnFact.setMaxConnections(1); + final PooledConnection connection1 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials"); try { @@ -122,19 +131,19 @@ public class PooledConnectionSecurityExceptionTest { @Override public boolean isSatisified() throws Exception { return connection1.getConnection() != - ((PooledConnection) pooledConnFact.createConnection("invalid", "credentials")).getConnection(); + ((PooledConnection) pooledConnFact.createConnection("invalid", "credentials")).getConnection(); } })); - PooledConnection connection2 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials"); + final PooledConnection connection2 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials"); + assertNotSame(connection1.getConnection(), connection2.getConnection()); + try { connection2.start(); fail("Should fail to connect"); } catch (JMSSecurityException ex) { LOG.info("Caught expected security error"); } - - assertNotSame(connection1.getConnection(), connection2.getConnection()); } @Test