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
This commit is contained in:
Gary Tully 2010-05-06 12:23:28 +00:00
parent 6e1d530029
commit d6bd98f4c7
1 changed files with 37 additions and 0 deletions

View File

@ -16,6 +16,9 @@
*/ */
package org.apache.activemq.pool; package org.apache.activemq.pool;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.jms.ExceptionListener; import javax.jms.ExceptionListener;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.Session; import javax.jms.Session;
@ -23,9 +26,13 @@ import javax.jms.TopicConnection;
import javax.jms.TopicPublisher; import javax.jms.TopicPublisher;
import javax.jms.TopicSession; import javax.jms.TopicSession;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; 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.command.ActiveMQTopic;
import org.apache.activemq.test.TestSupport; import org.apache.activemq.test.TestSupport;
import org.apache.activemq.util.SocketProxy;
/** /**
* @version $Revision$ * @version $Revision$
@ -59,6 +66,36 @@ public class PooledTopicPublisherTest extends TestSupport {
assertEquals(listener, connection.getExceptionListener()); 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 @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if (connection != null) { if (connection != null) {