[jboss-cvs] JBossAS SVN: r59643 - branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/callerscope.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jan 15 09:05:24 EST 2007
Author: flavia.rainone at jboss.com
Date: 2007-01-15 09:05:19 -0500 (Mon, 15 Jan 2007)
New Revision: 59643
Modified:
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/callerscope/CallerScopeTestCase.java
Log:
Fix random failures of CallerScopeTestCase on linux, due to garbage collector behaviour
Modified: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/callerscope/CallerScopeTestCase.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/callerscope/CallerScopeTestCase.java 2007-01-15 12:59:00 UTC (rev 59642)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/callerscope/CallerScopeTestCase.java 2007-01-15 14:05:19 UTC (rev 59643)
@@ -74,8 +74,10 @@
String a = new String("a");
String b = new String("a");
- String c = new String("a");
- String d = new String("a");
+ Flag cCollected = new Flag();
+ Object c = new GCTarget(cCollected);
+ Flag dCollected = new Flag();
+ Object d = new GCTarget(dCollected);
Long l1 = new Long(1);
Long l2 = new Long(2);
Long l3 = new Long(3);
@@ -99,6 +101,24 @@
c = null;
d = null;
System.gc();
+ // try to garbage collect c and d 31 times at most
+ for (int j = 0; j < 30 && !(cCollected.value && dCollected.value); j++) {
+ for (int i = 0; i < 10000; i++)
+ {
+ String string = new String("any string to fill memory space...");
+ }
+ System.gc();
+ try
+ {
+ Thread.sleep(10000);
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException("Unexpected exception, e");
+ }
+ }
+
+
assertEquals(2, map.size());
assertEquals(l1, map.get(a));
@@ -238,5 +258,32 @@
assertEquals("Wrong intercepted value for PerClassJoinpointAspect", perClassJoinpointAspect, PerClassJoinpointAspect.intercepted);
assertEquals("Wrong intercepted value for PerClassJoinpointInterceptor", perClassJoinpointInterceptor, PerClassJoinpointInterceptor.intercepted);
}
-
}
+
+/**
+ * Target of a garbage collection (used in weak hash map test).
+ *
+ * @author Flavia Rainone
+ */
+class GCTarget
+{
+ Flag collected;
+ public GCTarget(Flag collected)
+ {
+ this.collected = collected;
+ }
+
+ protected void finalize() throws Throwable
+ {
+ this.collected.value = true;
+ }
+}
+
+/**
+ * Helper class that stores a boolean value.
+ * @author Flavia Rainone
+ */
+class Flag
+{
+ boolean value = false;
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list