Added: activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledSessionTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledSessionTest.java?rev=1383746&view=auto ============================================================================== --- activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledSessionTest.java (added) +++ activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledSessionTest.java Wed Sep 12 03:44:48 2012 @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.pool; + +import static org.junit.Assert.assertEquals; + +import javax.jms.Session; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PooledSessionTest { + + private Logger LOG = Logger.getLogger(getClass()); + + private BrokerService broker; + private ActiveMQConnectionFactory factory; + private PooledConnectionFactory pooledFactory; + private String connectionUri; + + @Before + public void setUp() throws Exception { + broker = new BrokerService(); + broker.setPersistent(false); + broker.setUseJmx(false); + TransportConnector connector = broker.addConnector("tcp://localhost:0"); + broker.start(); + connectionUri = connector.getPublishableConnectString(); + factory = new ActiveMQConnectionFactory(connectionUri); + pooledFactory = new PooledConnectionFactory(factory); + pooledFactory.setMaxConnections(1); + pooledFactory.setBlockIfSessionPoolIsFull(false); + } + + @After + public void tearDown() throws Exception { + broker.stop(); + broker.waitUntilStopped(); + broker = null; + } + + @Test + public void testPooledSessionStats() throws Exception { + PooledConnection connection = (PooledConnection) pooledFactory.createConnection(); + + assertEquals(0, connection.getNumActiveSessions()); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + assertEquals(1, connection.getNumActiveSessions()); + session.close(); + assertEquals(0, connection.getNumActiveSessions()); + assertEquals(1, connection.getNumtIdleSessions()); + assertEquals(1, connection.getNumSessions()); + } + +}
Modified: activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java?rev=1383746&r1=1383745&r2=1383746&view=diff ============================================================================== --- activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java (original) +++ activemq/trunk/activemq-pool/src/test/java/org/apache/activemq/pool/PooledTopicPublisherTest.java Wed Sep 12 03:44:48 2012 @@ -35,7 +35,7 @@ import org.apache.activemq.test.TestSupp import org.apache.activemq.util.SocketProxy; /** - * + * */ public class PooledTopicPublisherTest extends TestSupport { @@ -52,7 +52,7 @@ public class PooledTopicPublisherTest ex publisher.publish(session.createMessage()); } - + public void testSetGetExceptionListener() throws Exception { PooledConnectionFactory pcf = new PooledConnectionFactory(); pcf.setConnectionFactory(new ActiveMQConnectionFactory("vm://test")); @@ -65,37 +65,37 @@ public class PooledTopicPublisherTest ex connection.setExceptionListener(listener); 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(); + assertNotNull(amq); 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) {
