[jboss-cvs] JBoss Messaging SVN: r2800 - in trunk: src/main/org/jboss/jms/client/state and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 25 21:45:51 EDT 2007
Author: clebert.suconic at jboss.com
Date: 2007-06-25 21:45:51 -0400 (Mon, 25 Jun 2007)
New Revision: 2800
Modified:
trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
trunk/src/main/org/jboss/jms/client/state/ConnectionState.java
trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-736 - fix and improve testcase
Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java 2007-06-25 23:03:21 UTC (rev 2799)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java 2007-06-26 01:45:51 UTC (rev 2800)
@@ -132,6 +132,11 @@
// There is one RM per server, so we need to merge the rms if necessary
ResourceManagerFactory.instance.handleFailover(serverID, newDelegate.getServerID());
+
+ // The remoting connection was replaced by a new one..
+ // we have to set the connection Delegate on the CallbackManager to avoid leaks
+ remotingConnection.getCallbackManager().setConnectionDelegate(this);
+
client = thisState.getRemotingConnection().getRemotingClient();
serverID = newDelegate.getServerID();
Modified: trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java 2007-06-25 23:03:21 UTC (rev 2799)
+++ trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java 2007-06-26 01:45:51 UTC (rev 2800)
@@ -247,7 +247,7 @@
return new MessagingJMSException("Failed to invoke", t);
}
-
+
public Client getClient()
{
return client;
Modified: trunk/src/main/org/jboss/jms/client/state/ConnectionState.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/state/ConnectionState.java 2007-06-25 23:03:21 UTC (rev 2799)
+++ trunk/src/main/org/jboss/jms/client/state/ConnectionState.java 2007-06-26 01:45:51 UTC (rev 2800)
@@ -152,7 +152,11 @@
idGenerator = newState.idGenerator;
serverID = newState.serverID;
versionToUse = newState.versionToUse;
-
+
+ // The remoting connection was replaced by a new one..
+ // we have to set the connection state on the ConnectionListener to avoid leaks
+ remotingConnection.getConnectionListener().setConnectionState(this);
+
ConnectionDelegate newDelegate = (ConnectionDelegate)newState.getDelegate();
for(Iterator i = getChildren().iterator(); i.hasNext(); )
Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java 2007-06-25 23:03:21 UTC (rev 2799)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java 2007-06-26 01:45:51 UTC (rev 2800)
@@ -29,12 +29,16 @@
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;
+import javax.jms.MessageProducer;
import org.jboss.jms.client.JBossConnection;
import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.jms.client.FailoverValve2;
import org.jboss.jms.client.delegate.DelegateSupport;
+import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.state.ProducerState;
+import org.jboss.jms.client.state.SessionState;
import org.jboss.profiler.jvmti.InventoryDataPoint;
import org.jboss.profiler.jvmti.JVMTIInterface;
import org.jboss.test.messaging.jms.clustering.base.ClusteringTestBase;
@@ -67,6 +71,51 @@
// Public ---------------------------------------------------------------------------------------
+ public void testValidateOpening() throws Exception
+ {
+ JVMTIInterface jvmti = new JVMTIInterface();
+
+
+ Map inventory1 = null;
+ Connection conn = null;
+ for (int i=0;i<100;i++)
+ {
+ System.out.println("Creating connection " + i);
+ conn = cf.createConnection();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue[0]);
+ MessageConsumer consumer = session.createConsumer(queue[0]);
+ conn.start();
+ Thread.sleep(100);
+ conn.close();
+
+ if (i==10)
+ {
+ inventory1 = jvmti.produceInventory();
+ }
+ }
+
+ conn = null;
+
+
+ jvmti.forceReleaseOnSoftReferences();
+ jvmti.forceGC();
+
+ Map inventory2 = jvmti.produceInventory();
+
+ validateInstances(jvmti, FailoverValve2.class, inventory2, 1);
+
+ assertTrue("Test produced unexpected objects", jvmti.compareInventories(System.out,
+ inventory1, inventory2, null, null,
+ new InventoryDataPoint[]{new InventoryDataPoint(java.lang.ref.SoftReference.class, 10),
+ new InventoryDataPoint(jvmti.getClassByName("java.io.ObjectStreamClass$WeakClassKey"), 100),
+ new InventoryDataPoint(jvmti.getClassByName("java.util.concurrent.ConcurrentHashMap$HashEntry"), 100),
+ new InventoryDataPoint(jvmti.getClassByName("java.util.WeakHashMap$Entry"), 500)
+
+ }));
+
+ }
+
public void testValidateFailover() throws Exception
{
Connection conn = null;
@@ -129,36 +178,12 @@
Map inventory2 = jvmti.produceInventory();
- InventoryDataPoint dataPoint = (InventoryDataPoint) inventory2.get(ProducerState.class);
- if (dataPoint.getInstances() > 1)
- {
- // We should only have this producerState... we will look for where are the
- // other references
- ProducerState originalState = (ProducerState )
- ((DelegateSupport)p1.getDelegate()).getState();
- Object obj[] = jvmti.getAllObjects(ProducerState.class);
+ validateInstances(jvmti, ClientConnectionDelegate.class, inventory2, 1);
+ validateInstances(jvmti, ConnectionState.class, inventory2, 1);
+ validateInstances(jvmti, MessageConsumer.class, inventory2, 1);
+ validateInstances(jvmti, ProducerState.class, inventory2, 1);
+ validateInstances(jvmti, FailoverValve2.class, inventory2, 1);
- for (int i = 0; i < obj.length; i++)
- {
- if (obj[i] != originalState)
- {
- log.info("Exploring references on " + obj[i]);
- Object[] holders = jvmti.getReferenceHolders(new Object[]{obj[i]});
-
- for (int j = 0; j < holders.length; j++)
- {
- log.info("Holder[" + j + "] = " + holders[j]);
- }
-
- }
- }
-
- }
-
- assertTrue("Test produced unexpected objects", jvmti.compareInventories(System.out,
- inventory1, inventory2, null, null,
- new InventoryDataPoint[]{new InventoryDataPoint(Object.class, 10)}));
-
}
finally
{
@@ -169,7 +194,19 @@
}
}
+ /** Look on the HEAP information if a given class produced more objects than expected.
+ * If it happened, a report will be generated on the System.out */
+ protected void validateInstances(JVMTIInterface jvmti, Class clazz, Map inventory, int maxExpectedResult)
+ {
+ InventoryDataPoint dataPoint = (InventoryDataPoint) inventory.get(clazz);
+ if (dataPoint != null && dataPoint.getInstances() > 1)
+ {
+ System.out.println(clazz.getName() + " report -> " + jvmti.exploreObjectReferences(clazz.getName(),5,true));
+ fail("Produced unexpected objects (" + dataPoint.getInstances() + " objects, while it was expecting " + maxExpectedResult + ") on " + clazz.getName());
+ }
+ }
+
// Package protected ----------------------------------------------------------------------------
// Protected ------------------------------------------------------------------------------------
More information about the jboss-cvs-commits
mailing list