[jboss-cvs] JBoss Messaging SVN: r7744 - in trunk/tests/src/org/jboss/messaging/tests: util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 17 00:28:11 EDT 2009
Author: clebert.suconic at jboss.com
Date: 2009-08-17 00:28:11 -0400 (Mon, 17 Aug 2009)
New Revision: 7744
Modified:
trunk/tests/src/org/jboss/messaging/tests/integration/client/SessionCloseOnGCTest.java
trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
Log:
Adding test on SessionCloseOnGCTest
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/SessionCloseOnGCTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/SessionCloseOnGCTest.java 2009-08-17 04:19:18 UTC (rev 7743)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/SessionCloseOnGCTest.java 2009-08-17 04:28:11 UTC (rev 7744)
@@ -21,6 +21,8 @@
*/
package org.jboss.messaging.tests.integration.client;
+import java.lang.ref.WeakReference;
+
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.ClientSessionFactory;
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
@@ -56,6 +58,52 @@
super.tearDown();
}
+
+ /** Make sure Sessions are not leaking after closed..
+ * Also... we want to make sure the SessionFactory will close itself when there are not references into it */
+ public void testValidateLeakWithClosedSessions() throws Exception
+ {
+ try
+ {
+ ClientSessionFactory factory = createInVMFactory();
+
+ ClientSession s1 = factory.createSession();
+ ClientSession s2 = factory.createSession();
+
+ s1.close();
+ s2.close();
+
+ WeakReference<ClientSession> wrs1 = new WeakReference<ClientSession>(s1);
+ WeakReference<ClientSession> wrs2 = new WeakReference<ClientSession>(s2);
+
+ s1 = null;
+
+ s2 = null;
+
+ checkWeakReferences(wrs1, wrs2);
+
+ WeakReference<ClientSessionFactory> fref = new WeakReference<ClientSessionFactory>(factory);
+
+ factory = null;
+
+ checkWeakReferences(fref, wrs1, wrs2);
+
+ }
+ finally
+ {
+ try
+ {
+ server.stop();
+ }
+ catch (Throwable ignored)
+ {
+
+ }
+ }
+
+ }
+
+
public void testCloseOneSessionOnGC() throws Exception
{
Modified: trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java 2009-08-17 04:19:18 UTC (rev 7743)
+++ trunk/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java 2009-08-17 04:28:11 UTC (rev 7744)
@@ -76,8 +76,8 @@
public static void forceGC()
{
- WeakReference dumbReference = new WeakReference(new Object());
- // A loopt that will wait GC, using the minimal time as possible
+ WeakReference<Object> dumbReference = new WeakReference<Object>(new Object());
+ // A loop that will wait GC, using the minimal time as possible
while (dumbReference.get() != null)
{
System.gc();
@@ -91,6 +91,33 @@
}
}
+ // verify if these weak references are released after a few GCs
+ public static void checkWeakReferences(WeakReference<?>... references)
+ {
+
+ int i = 0;
+ boolean hasValue = false;
+
+ do
+ {
+ hasValue = false;
+
+ if (i > 0)
+ {
+ forceGC();
+ }
+
+ for (WeakReference<?> ref : references)
+ {
+ if (ref.get() != null)
+ {
+ hasValue = true;
+ }
+ }
+ }
+ while (i++ <= 10 && hasValue);
+ }
+
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
More information about the jboss-cvs-commits
mailing list