Author: dennisl Date: Sun Sep 23 11:33:16 2012 New Revision: 1389022 URL: http://svn.apache.org/viewvc?rev=1389022&view=rev Log: Merge test for LOGGING-119 into the standard test class for WeakHashtable.
Removed: commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java Modified: commons/proper/logging/trunk/src/test/org/apache/commons/logging/impl/WeakHashtableTest.java Modified: commons/proper/logging/trunk/src/test/org/apache/commons/logging/impl/WeakHashtableTest.java URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/src/test/org/apache/commons/logging/impl/WeakHashtableTest.java?rev=1389022&r1=1389021&r2=1389022&view=diff ============================================================================== --- commons/proper/logging/trunk/src/test/org/apache/commons/logging/impl/WeakHashtableTest.java (original) +++ commons/proper/logging/trunk/src/test/org/apache/commons/logging/impl/WeakHashtableTest.java Sun Sep 23 11:33:16 2012 @@ -32,7 +32,13 @@ import junit.framework.TestCase; public class WeakHashtableTest extends TestCase { - + private static final int WAIT_FOR_THREAD_COMPLETION = 5000; // 5 seconds + private static final int RUN_LOOPS = 3000; + private static final int OUTER_LOOP = 400; + private static final int THREAD_COUNT = 10; + + private static WeakHashtable hashtable; + /** Maximum number of iterations before our test fails */ private static final int MAX_GC_ITERATIONS = 50; @@ -255,4 +261,47 @@ public class WeakHashtableTest extends T // Test that the released objects are not taking space in the table assertEquals("underlying table not emptied", 0, weakHashtable.size()); } + + public static class StupidThread extends Thread { + + public StupidThread(String name) { + super(name); + } + + public void run() { + for (int i = 0; i < RUN_LOOPS; i++) { + hashtable.put("key" + ":" + (i%10), Boolean.TRUE); + if(i%50 == 0) { + yield(); + } + } + } + } + + public void testLOGGING_119() throws Exception { + Thread [] t = new Thread[THREAD_COUNT]; + for (int j=1; j <= OUTER_LOOP; j++) { + hashtable = new WeakHashtable(); + for (int i = 0; i < t.length; i++) { + t[i] = new StupidThread("Thread:" + i); + t[i].setDaemon(true); // Otherwise we cannot exit + t[i].start(); + } + for (int i = 0; i < t.length; i++) { + t[i].join(WAIT_FOR_THREAD_COMPLETION); + if (t[i].isAlive()) { + break; // at least one thread is stuck + } + } + int active=0; + for (int i = 0; i < t.length; i++) { + if (t[i].isAlive()) { + active++; + } + } + if (active > 0) { + fail("Attempt: " + j + " Stuck threads: " + active); + } + } + } }