mirror of https://github.com/apache/activemq.git
Ensure all PooledConnectionFactory instances are stopped at tests end to
ensure that pooled connections are all closed to release VM Transport resrouces
This commit is contained in:
parent
28e7cb0b21
commit
27ce49f1c8
|
@ -28,6 +28,7 @@ import javax.jms.Session;
|
|||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -54,6 +55,18 @@ public class ConnectionExpiryEvictsFromPoolTest extends JmsPoolTestSupport {
|
|||
pooledFactory.setMaxConnections(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
pooledFactory.stop();
|
||||
} catch (Exception ex) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testEvictionOfIdle() throws Exception {
|
||||
pooledFactory.setIdleTimeout(10);
|
||||
|
|
|
@ -88,6 +88,8 @@ public class PooledConnectionFactoryMaximumActiveTest extends JmsPoolTestSupport
|
|||
|
||||
// Take all threads down
|
||||
executor.shutdownNow();
|
||||
|
||||
cf.stop();
|
||||
}
|
||||
|
||||
static class TestRunner2 implements Callable<Boolean> {
|
||||
|
|
|
@ -63,6 +63,7 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
PooledConnectionFactory pcf = new PooledConnectionFactory();
|
||||
assertTrue(pcf instanceof QueueConnectionFactory);
|
||||
assertTrue(pcf instanceof TopicConnectionFactory);
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -95,6 +96,8 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
assertNotSame(conn1.getConnection(), conn2.getConnection());
|
||||
assertNotSame(conn1.getConnection(), conn3.getConnection());
|
||||
assertNotSame(conn2.getConnection(), conn3.getConnection());
|
||||
|
||||
cf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -115,6 +118,8 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
assertNotSame(conn2.getConnection(), conn3.getConnection());
|
||||
|
||||
assertEquals(3, cf.getNumConnections());
|
||||
|
||||
cf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -138,6 +143,8 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
assertNotSame(previous, current);
|
||||
previous = current;
|
||||
}
|
||||
|
||||
cf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -157,6 +164,8 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
assertSame(conn2.getConnection(), conn3.getConnection());
|
||||
|
||||
assertEquals(1, cf.getNumConnections());
|
||||
|
||||
cf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -308,11 +317,13 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
Connection conn = null;
|
||||
Session one = null;
|
||||
|
||||
PooledConnectionFactory cf = null;
|
||||
|
||||
// wait at most 5 seconds for the call to createSession
|
||||
try {
|
||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory(
|
||||
"vm://broker1?marshal=false&broker.persistent=false&broker.useJmx=false");
|
||||
PooledConnectionFactory cf = new PooledConnectionFactory();
|
||||
cf = new PooledConnectionFactory();
|
||||
cf.setConnectionFactory(amq);
|
||||
cf.setMaxConnections(3);
|
||||
cf.setMaximumActiveSessionPerConnection(1);
|
||||
|
@ -351,6 +362,10 @@ public class PooledConnectionFactoryTest extends JmsPoolTestSupport {
|
|||
} catch (Exception ex) {
|
||||
LOG.error(ex.getMessage());
|
||||
return new Boolean(false);
|
||||
} finally {
|
||||
if (cf != null) {
|
||||
cf.stop();
|
||||
}
|
||||
}
|
||||
|
||||
// all good, test succeeded
|
||||
|
|
|
@ -34,6 +34,7 @@ import javax.jms.Session;
|
|||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -57,6 +58,18 @@ public class PooledConnectionFailoverTest extends JmsPoolTestSupport {
|
|||
pooledConnFact.setReconnectOnException(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
pooledConnFact.stop();
|
||||
} catch (Exception ex) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionFailures() throws Exception {
|
||||
|
||||
|
|
|
@ -79,6 +79,8 @@ public class PooledConnectionSecurityExceptionTest {
|
|||
connection.start();
|
||||
|
||||
LOG.info("Successfully create new connection.");
|
||||
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -103,6 +105,8 @@ public class PooledConnectionSecurityExceptionTest {
|
|||
connection.start();
|
||||
|
||||
LOG.info("Successfully create new connection.");
|
||||
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -143,7 +147,11 @@ public class PooledConnectionSecurityExceptionTest {
|
|||
fail("Should fail to connect");
|
||||
} catch (JMSSecurityException ex) {
|
||||
LOG.info("Caught expected security error");
|
||||
} finally {
|
||||
connection2.close();
|
||||
}
|
||||
|
||||
connection1.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -167,6 +175,9 @@ public class PooledConnectionSecurityExceptionTest {
|
|||
}
|
||||
|
||||
assertNotSame(connection1, connection2);
|
||||
|
||||
connection1.close();
|
||||
connection2.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -192,6 +203,8 @@ public class PooledConnectionSecurityExceptionTest {
|
|||
connection.start();
|
||||
|
||||
LOG.info("Successfully create new connection.");
|
||||
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -233,7 +246,11 @@ public class PooledConnectionSecurityExceptionTest {
|
|||
} catch (JMSSecurityException ex) {
|
||||
LOG.info("Caught expected security error");
|
||||
connection2.close();
|
||||
} finally {
|
||||
connection2.close();
|
||||
}
|
||||
|
||||
connection1.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -68,6 +68,8 @@ public class PooledConnectionTempQueueTest extends JmsPoolTestSupport {
|
|||
});
|
||||
|
||||
sendWithReplyToTemp(cf, SERVICE_QUEUE);
|
||||
|
||||
cf.stop();
|
||||
}
|
||||
|
||||
private void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException,
|
||||
|
|
|
@ -57,10 +57,11 @@ public class PooledConnectionTest extends JmsPoolTestSupport {
|
|||
conn.setClientID("newID");
|
||||
conn.start();
|
||||
conn.close();
|
||||
cf = null;
|
||||
} catch (IllegalStateException ise) {
|
||||
LOG.error("Repeated calls to ActiveMQConnection.setClientID(\"newID\") caused " + ise.getMessage());
|
||||
fail("Repeated calls to ActiveMQConnection.setClientID(\"newID\") caused " + ise.getMessage());
|
||||
} finally {
|
||||
((PooledConnectionFactory) cf).stop();
|
||||
}
|
||||
|
||||
// 2nd test: call setClientID() twice with different IDs
|
||||
|
@ -76,6 +77,7 @@ public class PooledConnectionTest extends JmsPoolTestSupport {
|
|||
LOG.debug("Correctly received " + ise);
|
||||
} finally {
|
||||
conn.close();
|
||||
((PooledConnectionFactory) cf).stop();
|
||||
}
|
||||
|
||||
// 3rd test: try to call setClientID() after start()
|
||||
|
@ -90,6 +92,7 @@ public class PooledConnectionTest extends JmsPoolTestSupport {
|
|||
LOG.debug("Correctly received " + ise);
|
||||
} finally {
|
||||
conn.close();
|
||||
((PooledConnectionFactory) cf).stop();
|
||||
}
|
||||
|
||||
LOG.debug("Test finished.");
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PooledSessionExhaustionBlockTimeoutTest extends JmsPoolTestSupport {
|
||||
|
@ -75,6 +76,18 @@ public class PooledSessionExhaustionBlockTimeoutTest extends JmsPoolTestSupport
|
|||
pooledFactory.setMaximumActiveSessionPerConnection(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
pooledFactory.stop();
|
||||
} catch (Exception ex) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
class TestRunner implements Runnable {
|
||||
|
||||
CyclicBarrier barrier;
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -74,6 +75,18 @@ public class PooledSessionExhaustionTest extends JmsPoolTestSupport {
|
|||
pooledFactory.setMaximumActiveSessionPerConnection(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
pooledFactory.stop();
|
||||
} catch (Exception ex) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
class TestRunner implements Runnable {
|
||||
|
||||
CyclicBarrier barrier;
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.jms.TopicSession;
|
|||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -59,6 +60,18 @@ public class PooledSessionNoPublisherCachingTest extends JmsPoolTestSupport {
|
|||
pooledFactory.setUseAnonymousProducers(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
pooledFactory.stop();
|
||||
} catch (Exception ex) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testMessageProducersAreUnique() throws Exception {
|
||||
PooledConnection connection = (PooledConnection) pooledFactory.createConnection();
|
||||
|
|
|
@ -33,6 +33,7 @@ import javax.jms.TopicSession;
|
|||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -64,6 +65,18 @@ public class PooledSessionTest extends JmsPoolTestSupport {
|
|||
pooledFactory.setBlockIfSessionPoolIsFull(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
pooledFactory.stop();
|
||||
} catch (Exception ex) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testPooledSessionStats() throws Exception {
|
||||
PooledConnection connection = (PooledConnection) pooledFactory.createConnection();
|
||||
|
|
|
@ -43,22 +43,31 @@ import org.junit.Test;
|
|||
public class PooledTopicPublisherTest extends JmsPoolTestSupport {
|
||||
|
||||
private TopicConnection connection;
|
||||
private PooledConnectionFactory pcf;
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception ex) {}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
if (pcf != null) {
|
||||
try {
|
||||
pcf.stop();
|
||||
} catch (Exception ex) {}
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testPooledConnectionFactory() throws Exception {
|
||||
ActiveMQTopic topic = new ActiveMQTopic("test");
|
||||
PooledConnectionFactory pcf = new PooledConnectionFactory();
|
||||
pcf = new PooledConnectionFactory();
|
||||
pcf.setConnectionFactory(new ActiveMQConnectionFactory(
|
||||
"vm://test?broker.persistent=false&broker.useJmx=false"));
|
||||
|
||||
|
@ -70,7 +79,7 @@ public class PooledTopicPublisherTest extends JmsPoolTestSupport {
|
|||
|
||||
@Test(timeout = 60000)
|
||||
public void testSetGetExceptionListener() throws Exception {
|
||||
PooledConnectionFactory pcf = new PooledConnectionFactory();
|
||||
pcf = new PooledConnectionFactory();
|
||||
pcf.setConnectionFactory(new ActiveMQConnectionFactory(
|
||||
"vm://test?broker.persistent=false&broker.useJmx=false"));
|
||||
|
||||
|
@ -97,7 +106,7 @@ public class PooledTopicPublisherTest extends JmsPoolTestSupport {
|
|||
|
||||
SocketProxy proxy = new SocketProxy(networkConnector.getConnectUri());
|
||||
|
||||
PooledConnectionFactory pcf = new PooledConnectionFactory();
|
||||
pcf = new PooledConnectionFactory();
|
||||
String uri = proxy.getUrl().toString() + "?trace=true&wireFormat.maxInactivityDuration=500&wireFormat.maxInactivityDurationInitalDelay=500";
|
||||
pcf.setConnectionFactory(new ActiveMQConnectionFactory(uri));
|
||||
|
||||
|
|
|
@ -156,6 +156,8 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
sync.afterCompletion(1);
|
||||
}
|
||||
connection.close();
|
||||
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -256,6 +258,7 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
sync.afterCompletion(1);
|
||||
}
|
||||
connection.close();
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -263,6 +266,7 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
XaPooledConnectionFactory pcf = new XaPooledConnectionFactory();
|
||||
assertTrue(pcf instanceof QueueConnectionFactory);
|
||||
assertTrue(pcf instanceof TopicConnectionFactory);
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -271,6 +275,7 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
assertTrue(pcf instanceof ObjectFactory);
|
||||
assertTrue(((ObjectFactory)pcf).getObjectInstance(null, null, null, null) instanceof XaPooledConnectionFactory);
|
||||
assertTrue(pcf.isTmFromJndi());
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -281,6 +286,7 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
environment.put("tmFromJndi", String.valueOf(Boolean.FALSE));
|
||||
assertTrue(((ObjectFactory) pcf).getObjectInstance(null, null, null, environment) instanceof XaPooledConnectionFactory);
|
||||
assertFalse(pcf.isTmFromJndi());
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -302,6 +308,7 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
assertNotNull(topicPublisher.getTopic().getTopicName());
|
||||
|
||||
topicConnection.close();
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
@Test(timeout = 60000)
|
||||
|
@ -362,6 +369,7 @@ public class XAConnectionPoolTest extends JmsPoolTestSupport {
|
|||
assertNotNull("can create session(false, 0)", connection.createQueueSession(false, 0));
|
||||
|
||||
connection.close();
|
||||
pcf.stop();
|
||||
}
|
||||
|
||||
static class XAConnectionFactoryOnly implements XAConnectionFactory {
|
||||
|
|
Loading…
Reference in New Issue