AMQ-7233 - ensure sessions are cleaned up on pooledconnection.close before temp dests to ensure temp dests actually get deleted, fix and test

This commit is contained in:
gtully 2019-06-19 10:29:11 +01:00
parent dc56fa3f6e
commit efc857fc1f
2 changed files with 20 additions and 1 deletions

View File

@ -81,8 +81,8 @@ public class PooledConnection implements TopicConnection, QueueConnection, Poole
@Override
public void close() throws JMSException {
this.cleanupConnectionTemporaryDestinations();
this.cleanupAllLoanedSessions();
this.cleanupConnectionTemporaryDestinations();
if (this.pool != null) {
this.pool.decrementReferenceCount();
this.pool = null;

View File

@ -19,6 +19,7 @@ package org.apache.activemq.jms.pool;
import static org.junit.Assert.assertEquals;
import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
@ -119,6 +120,24 @@ public class PooledConnectionFactoryWithTemporaryDestinationsTest extends JmsPoo
assertEquals(0, countBrokerTemporaryTopics());
}
@Test(timeout = 60000)
public void testTemporaryQueueLeakAfterConnectionCloseWithConsumer() throws Exception {
Connection pooledConnection = null;
Session session = null;
Queue tempQueue = null;
for (int i = 0; i < 2; i++) {
pooledConnection = pooledFactory.createConnection();
session = pooledConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
tempQueue = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(tempQueue);
consumer.receiveNoWait();
LOG.info("Created queue named: " + tempQueue.getQueueName());
pooledConnection.close();
}
assertEquals(0, countBrokerTemporaryQueues());
}
private int countBrokerTemporaryQueues() throws Exception {
return ((RegionBroker) brokerService.getRegionBroker()).getTempQueueRegion().getDestinationMap().size();
}