Author: clebert.suconic(a)jboss.com
Date: 2012-01-05 12:42:06 -0500 (Thu, 05 Jan 2012)
New Revision: 11979
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java
Log:
JBPAPP-7856 - fix on test
Modified:
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java
===================================================================
---
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java 2012-01-05
16:28:35 UTC (rev 11978)
+++
branches/Branch_2_2_EAP/tests/src/org/hornetq/tests/unit/util/LinkedListTest.java 2012-01-05
17:42:06 UTC (rev 11979)
@@ -13,6 +13,8 @@
package org.hornetq.tests.unit.util;
+import java.lang.ref.WeakReference;
+import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -90,28 +92,12 @@
if (i % 1000 == 0)
{
System.out.println("Checking on " + i);
-
- for (int gcLoop = 0 ; gcLoop < 5; gcLoop++)
- {
- forceGC();
- if (count.get() == 1000)
- {
- break;
- }
- else
- {
- System.out.println("Trying a GC again");
- }
- }
-
- assertEquals(1000, count.get());
+ assertCount(1000, count);
}
}
- forceGC();
+ assertCount(1000, count);
- assertEquals(1000, count.get());
-
int removed = 0;
while (iter.hasNext())
{
@@ -119,11 +105,44 @@
iter.next();
iter.remove();
}
+
+ assertCount(0, count);
- forceGC();
+ }
- assertEquals(0, count.get());
+ /**
+ * @param count
+ */
+ private void assertCount(final int expected, final AtomicInteger count)
+ {
+ long timeout = System.currentTimeMillis() + 5000;
+
+ int seqCount = 0;
+ while (timeout > System.currentTimeMillis() && count.get() != expected)
+ {
+ seqCount ++;
+ if (seqCount > 5)
+ {
+ LinkedList<String> toOME = new LinkedList<String>();
+ int someCount = 0;
+ try
+ {
+ WeakReference<Object> ref = new WeakReference<Object>(new
Object());
+ while (ref.get() != null)
+ {
+ toOME.add("sdlfkjshadlfkjhas dlfkjhas dlfkjhads lkjfhads lfkjhads
flkjashdf " + someCount++);
+ }
+ }
+ catch (Throwable expectedThrowable)
+ {
+ }
+
+ toOME.clear();
+ }
+ forceGC();
+ }
+ assertEquals(expected, count.get());
}
public void testAddTail()