Author: veithen
Date: Sun Oct 21 13:25:00 2012
New Revision: 1400644

URL: http://svn.apache.org/viewvc?rev=1400644&view=rev
Log:
* Attempt to increase the probability of observing the issue described in 
AXIS-2498 in MultithreadTestCase.
* Ensure that MultithreadTestCase will report hanging threads (instead of 
blocking the build).

Modified:
    
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/Invoker.java
    
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/MultithreadTestCase.java

Modified: 
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/Invoker.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/Invoker.java?rev=1400644&r1=1400643&r2=1400644&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/Invoker.java
 (original)
+++ 
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/Invoker.java
 Sun Oct 21 13:25:00 2012
@@ -18,6 +18,8 @@
  */
 package test.wsdl.multithread;
 
+import java.util.concurrent.CountDownLatch;
+
 import org.apache.axis.components.logger.LogFactory;
 import org.apache.commons.logging.Log;
 
@@ -30,15 +32,24 @@ class Invoker implements Runnable {
     private static Log log = LogFactory.getLog(Invoker.class.getName());
     
     private final AddressBook binding;
+    private final CountDownLatch readyLatch;
+    private final CountDownLatch startLatch;
     private final Report report;
     
-    Invoker(AddressBook binding, Report report) {
+    Invoker(AddressBook binding, CountDownLatch readyLatch, CountDownLatch 
startLatch, Report report) {
         this.binding = binding;
+        this.readyLatch = readyLatch;
+        this.startLatch = startLatch;
         this.report = report;
     }
 
     public void run() {
         try {
+            // This ensures that all threads start sending requests at the 
same time,
+            // thereby increasing the probability of triggering a concurrency 
issue.
+            readyLatch.countDown();
+            startLatch.await();
+            
             for (int i = 0; i < 4; ++i) {
                 Address address = new Address();
                 Phone phone = new Phone();

Modified: 
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/MultithreadTestCase.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/MultithreadTestCase.java?rev=1400644&r1=1400643&r2=1400644&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/MultithreadTestCase.java
 (original)
+++ 
axis/axis1/java/trunk/integration/src/test/java/test/wsdl/multithread/MultithreadTestCase.java
 Sun Oct 21 13:25:00 2012
@@ -1,5 +1,7 @@
 package test.wsdl.multithread;
 
+import java.util.concurrent.CountDownLatch;
+
 import junit.framework.TestCase;
 import samples.addr.AddressBook;
 import samples.addr.AddressBookSOAPBindingStub;
@@ -44,16 +46,22 @@ public class MultithreadTestCase extends
     private void testMultithreading(StubSupplier stubSupplier) throws 
Throwable {
         Report report = new Report();
         int NUM_THREADS = 50;
+        CountDownLatch readyLatch = new CountDownLatch(NUM_THREADS);
+        CountDownLatch startLatch = new CountDownLatch(1);
         Thread[] threads = new Thread[NUM_THREADS];
         for (int i = 0; i < NUM_THREADS; ++i) {
-            threads[i] = new Thread(new Invoker(stubSupplier.getStub(), 
report));
+            threads[i] = new Thread(new Invoker(stubSupplier.getStub(), 
readyLatch, startLatch, report));
             threads[i].start();
         }
+        readyLatch.await();
+        startLatch.countDown();
         for (int i = 0; i < NUM_THREADS; ++i) {
-            try {
-                threads[i].join();
-            }
-            catch (InterruptedException ie) {
+            threads[i].join(30000);
+            StackTraceElement[] stack = threads[i].getStackTrace();
+            if (stack.length > 0) {
+                Throwable t = new Throwable("Hanging thread detected");
+                t.setStackTrace(stack);
+                throw t;
             }
         }
         Throwable error = report.getError();


Reply via email to