diff --git a/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java b/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java index a9e454ac52..797eb37d13 100644 --- a/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java +++ b/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java @@ -16,6 +16,9 @@ */ package org.apache.activemq.pool; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.Session; @@ -23,9 +26,13 @@ import javax.jms.TopicConnection; import javax.jms.TopicPublisher; import javax.jms.TopicSession; +import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.test.TestSupport; +import org.apache.activemq.util.SocketProxy; /** * @version $Revision$ @@ -59,6 +66,36 @@ public class PooledTopicPublisherTest extends TestSupport { assertEquals(listener, connection.getExceptionListener()); } + public void testPooledConnectionAfterInactivity() throws Exception { + BrokerService broker = new BrokerService(); + TransportConnector networkConnector = broker.addConnector("tcp://localhost:0"); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.start(); + + SocketProxy proxy = new SocketProxy(networkConnector.getConnectUri()); + + PooledConnectionFactory pcf = new PooledConnectionFactory(); + String uri = proxy.getUrl().toString() + "?trace=true&wireFormat.maxInactivityDuration=500&wireFormat.maxInactivityDurationInitalDelay=500"; + pcf.setConnectionFactory(new ActiveMQConnectionFactory(uri)); + + PooledConnection conn = (PooledConnection) pcf.createConnection(); + ActiveMQConnection amq = conn.getConnection(); + final CountDownLatch gotException = new CountDownLatch(1); + //amq.set + conn.setExceptionListener(new ExceptionListener() { + public void onException(JMSException exception) { + gotException.countDown(); + }}); + conn.setClientID(getName()); + + // let it hang, simulate a server hang so inactivity timeout kicks in + proxy.pause(); + //assertTrue("got an exception", gotException.await(5, TimeUnit.SECONDS)); + TimeUnit.SECONDS.sleep(2); + conn.close(); + } + @Override protected void tearDown() throws Exception { if (connection != null) {