diff --git a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java index 839d66845b..2e24be53b1 100644 --- a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java +++ b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java @@ -301,6 +301,7 @@ public class PooledConnectionFactory implements ConnectionFactory, QueueConnecti try { if (connectionsPool != null) { connectionsPool.close(); + connectionsPool = null; } } catch (Exception e) { } diff --git a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java index e06a6e1dce..94a563ce46 100644 --- a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java +++ b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java @@ -18,6 +18,7 @@ package org.apache.activemq.jms.pool; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -117,6 +118,32 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport { assertEquals(3, cf.getNumConnections()); } + @Test(timeout = 60000) + public void testFactoryStopStart() throws Exception { + + ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory( + "vm://broker1?marshal=false&broker.persistent=false&broker.useJmx=false"); + PooledConnectionFactory cf = new PooledConnectionFactory(); + cf.setConnectionFactory(amq); + cf.setMaxConnections(1); + + PooledConnection conn1 = (PooledConnection) cf.createConnection(); + + cf.stop(); + + assertNull(cf.createConnection()); + + cf.start(); + + PooledConnection conn2 = (PooledConnection) cf.createConnection(); + + assertNotSame(conn1.getConnection(), conn2.getConnection()); + + assertEquals(1, cf.getNumConnections()); + + cf.stop(); + } + @Test(timeout = 60000) public void testConnectionsAreRotated() throws Exception {