Ensure that connections created with vm Transport connections get

closed.
This commit is contained in:
Timothy Bish 2016-06-09 14:50:40 -04:00
parent 98d2000833
commit c9b208f0a3
3 changed files with 13 additions and 3 deletions

View File

@ -72,6 +72,8 @@ public class ActiveMQConnectionFactoryTest {
ActiveMQConnection connection = ((ActiveMQConnection) ((ManagedConnectionProxy) con).getManagedConnection().getPhysicalConnection()); ActiveMQConnection connection = ((ActiveMQConnection) ((ManagedConnectionProxy) con).getManagedConnection().getPhysicalConnection());
assertEquals(100, connection.getPrefetchPolicy().getQueuePrefetch()); assertEquals(100, connection.getPrefetchPolicy().getQueuePrefetch());
assertNotNull("Connection object returned by ActiveMQConnectionFactory.createConnection() is null", con); assertNotNull("Connection object returned by ActiveMQConnectionFactory.createConnection() is null", con);
connection.close();
} }
@Test(timeout = 60000) @Test(timeout = 60000)
@ -92,6 +94,8 @@ public class ActiveMQConnectionFactoryTest {
con.start(); con.start();
assertEquals(0, ((ActiveMQTopicSubscriber) sub).getPrefetchNumber()); assertEquals(0, ((ActiveMQTopicSubscriber) sub).getPrefetchNumber());
con.close();
} }
@Test(timeout = 60000) @Test(timeout = 60000)

View File

@ -51,7 +51,6 @@ public class ManagedConnectionTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
managedConnectionFactory = new ActiveMQManagedConnectionFactory(); managedConnectionFactory = new ActiveMQManagedConnectionFactory();
managedConnectionFactory.setServerUrl(DEFAULT_HOST); managedConnectionFactory.setServerUrl(DEFAULT_HOST);
managedConnectionFactory.setUserName(ActiveMQConnectionFactory.DEFAULT_USER); managedConnectionFactory.setUserName(ActiveMQConnectionFactory.DEFAULT_USER);
@ -60,7 +59,6 @@ public class ManagedConnectionTest {
connectionFactory = (ConnectionFactory)managedConnectionFactory.createConnectionFactory(connectionManager); connectionFactory = (ConnectionFactory)managedConnectionFactory.createConnectionFactory(connectionManager);
connection = (ManagedConnectionProxy)connectionFactory.createConnection(); connection = (ManagedConnectionProxy)connectionFactory.createConnection();
managedConnection = connection.getManagedConnection(); managedConnection = connection.getManagedConnection();
} }
@After @After
@ -106,7 +104,6 @@ public class ManagedConnectionTest {
session.commit(); session.commit();
assertTrue(test[0]); assertTrue(test[0]);
} }
@Test(timeout = 60000) @Test(timeout = 60000)
@ -254,6 +251,7 @@ public class ManagedConnectionTest {
public void testSamePropertiesButNotEqual() throws Exception { public void testSamePropertiesButNotEqual() throws Exception {
ManagedConnectionProxy newConnection = (ManagedConnectionProxy)connectionFactory.createConnection(); ManagedConnectionProxy newConnection = (ManagedConnectionProxy)connectionFactory.createConnection();
assertNonEquality(managedConnection, newConnection.getManagedConnection()); assertNonEquality(managedConnection, newConnection.getManagedConnection());
newConnection.close();
} }
private void assertEquality(ActiveMQManagedConnection leftCon, ActiveMQManagedConnection rightCon) { private void assertEquality(ActiveMQManagedConnection leftCon, ActiveMQManagedConnection rightCon) {

View File

@ -29,6 +29,7 @@ import javax.resource.ResourceException;
import javax.transaction.xa.XAException; import javax.transaction.xa.XAException;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -51,6 +52,13 @@ public class UnsubscribeResubscribeTest {
managedConnectionFactory.setClientid("clientId"); managedConnectionFactory.setClientid("clientId");
} }
@After
public void tearDown() throws Exception {
if (connection != null) {
connection.close();
}
}
private void getConnection() throws ResourceException, JMSException { private void getConnection() throws ResourceException, JMSException {
connectionFactory = (ConnectionFactory)managedConnectionFactory.createConnectionFactory(connectionManager); connectionFactory = (ConnectionFactory)managedConnectionFactory.createConnectionFactory(connectionManager);
connection = (ManagedConnectionProxy)connectionFactory.createConnection(); connection = (ManagedConnectionProxy)connectionFactory.createConnection();