From d6bd98f4c7d7889cc61477ea4ea5f648082e7f32 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Thu, 6 May 2010 12:23:28 +0000 Subject: [PATCH] test for pooled connection with inactive timouet on connection, close still works ok git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@941692 13f79535-47bb-0310-9956-ffa450edef68 --- .../pool/PooledTopicPublisherTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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) {