You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/07/17 18:11:25 UTC

svn commit: r1362553 - in /commons/proper/logging/trunk: pom.xml src/test/org/apache/commons/logging/WeakHashTableTestCase.java

Author: sebb
Date: Tue Jul 17 16:11:25 2012
New Revision: 1362553

URL: http://svn.apache.org/viewvc?rev=1362553&view=rev
Log:
LOGGING-119 deadlock on re-registration of logger
Added test case showing the problem

Added:
    commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java   (with props)
Modified:
    commons/proper/logging/trunk/pom.xml

Modified: commons/proper/logging/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/pom.xml?rev=1362553&r1=1362552&r2=1362553&view=diff
==============================================================================
--- commons/proper/logging/trunk/pom.xml (original)
+++ commons/proper/logging/trunk/pom.xml Tue Jul 17 16:11:25 2012
@@ -328,6 +328,7 @@ under the License.
         <configuration>
           <includes>
             <include>**/AvalonLoggerTestCase.java</include>
+            <include>**/WeakHashTableTestCase.java</include>
           </includes>
         </configuration>
 

Added: commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java?rev=1362553&view=auto
==============================================================================
--- commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java (added)
+++ commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java Tue Jul 17 16:11:25 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+ 
+package org.apache.commons.logging;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.impl.WeakHashtable;
+
+public class WeakHashTableTestCase  extends TestCase {
+
+    private static final int WAIT_FOR_THREAD_COMPLETION = 5000; // 5 seconds
+    private static final int RUN_LOOPS = 1500;
+    private static final int OUTER_LOOP = 100;
+    private static final int THREAD_COUNT = 10;
+    
+    private static WeakHashtable hashtable;
+
+    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);
+            }
+        }
+    }
+}

Propchange: commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/logging/trunk/src/test/org/apache/commons/logging/WeakHashTableTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision