Close failed connection on start if the reconnect on exception flag is
enabled.
This commit is contained in:
Timothy Bish 2016-05-11 16:03:19 -04:00
parent e53e340262
commit 2e64abc38a
2 changed files with 16 additions and 4 deletions

View File

@ -125,6 +125,9 @@ public class ConnectionPool implements ExceptionListener {
connection.start(); connection.start();
} catch (JMSException e) { } catch (JMSException e) {
started.set(false); started.set(false);
if (isReconnectOnException()) {
close();
}
throw(e); throw(e);
} }
} }

View File

@ -105,8 +105,17 @@ public class PooledConnectionSecurityExceptionTest {
LOG.info("Successfully create new connection."); LOG.info("Successfully create new connection.");
} }
@Test
public void testFailureGetsNewConnectionOnRetryLooped() throws Exception {
for (int i = 0; i < 10; ++i) {
testFailureGetsNewConnectionOnRetry();
}
}
@Test @Test
public void testFailureGetsNewConnectionOnRetry() throws Exception { public void testFailureGetsNewConnectionOnRetry() throws Exception {
pooledConnFact.setMaxConnections(1);
final PooledConnection connection1 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials"); final PooledConnection connection1 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials");
try { try {
@ -126,15 +135,15 @@ public class PooledConnectionSecurityExceptionTest {
} }
})); }));
PooledConnection connection2 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials"); final PooledConnection connection2 = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials");
assertNotSame(connection1.getConnection(), connection2.getConnection());
try { try {
connection2.start(); connection2.start();
fail("Should fail to connect"); fail("Should fail to connect");
} catch (JMSSecurityException ex) { } catch (JMSSecurityException ex) {
LOG.info("Caught expected security error"); LOG.info("Caught expected security error");
} }
assertNotSame(connection1.getConnection(), connection2.getConnection());
} }
@Test @Test