fix of the test (still failing) and better debug output editor_api_full_20060314
authorjtulach@netbeans.org
Thu, 02 Mar 2006 15:12:28 +0000
changeset 122bad302198bf5
parent 121 a761cd35c7e6
child 123 074fe5298ddf
fix of the test (still failing) and better debug output
openide.util/test/unit/src/org/openide/util/MutexTest.java
     1.1 --- a/openide.util/test/unit/src/org/openide/util/MutexTest.java	Tue Feb 28 18:11:25 2006 +0000
     1.2 +++ b/openide.util/test/unit/src/org/openide/util/MutexTest.java	Thu Mar 02 15:12:28 2006 +0000
     1.3 @@ -13,8 +13,12 @@
     1.4  
     1.5  package org.openide.util;
     1.6  
     1.7 +import java.io.ByteArrayOutputStream;
     1.8  import java.io.IOException;
     1.9 +import java.io.PrintStream;
    1.10  import java.lang.ref.*;
    1.11 +import java.lang.reflect.InvocationTargetException;
    1.12 +import java.lang.reflect.Method;
    1.13  import java.util.*;
    1.14  import org.openide.ErrorManager;
    1.15  import junit.framework.*;
    1.16 @@ -524,7 +528,7 @@
    1.17          final Ticker tickX2 = new Ticker();     
    1.18          final Ticker tickX3 = new Ticker();     
    1.19          
    1.20 -        Thread A = new Thread() { public void run() {
    1.21 +        Thread A = new Thread("A") { public void run() {
    1.22              PR.enterReadAccess();
    1.23              
    1.24              tickX1.tick();
    1.25 @@ -533,9 +537,11 @@
    1.26              synchronized(L) {
    1.27                  done[0] = true;
    1.28              }
    1.29 +
    1.30 +            PR.exitReadAccess();
    1.31          }};
    1.32                 
    1.33 -        Thread B = new Thread() { public void run() {
    1.34 +        Thread B = new Thread("B") { public void run() {
    1.35              synchronized(L) {
    1.36                  
    1.37                  tickX2.tick();
    1.38 @@ -548,7 +554,7 @@
    1.39              }
    1.40          }};
    1.41  
    1.42 -        Thread C = new Thread() { public void run() {
    1.43 +        Thread C = new Thread("C") { public void run() {
    1.44              PR.enterReadAccess();
    1.45              M.postWriteRequest(new Runnable() {public void run() {
    1.46                     done[2] = true;
    1.47 @@ -574,10 +580,19 @@
    1.48          A.join(2000);
    1.49          B.join(2000);
    1.50          C.join(2000);
    1.51 -        
    1.52 -        assertTrue("Thread A finished", done[0]);
    1.53 -        assertTrue("Thread B finished", done[1]);
    1.54 -        assertTrue("Thread C finished", done[2]);
    1.55 +
    1.56 +        if (!done[0] || !done[1] || !done[2]) {
    1.57 +            StringBuffer sb = new StringBuffer();
    1.58 +            sb.append("A: "); sb.append(done[0]);
    1.59 +            sb.append(" B: "); sb.append(done[1]);
    1.60 +            sb.append(" C: "); sb.append(done[2]);
    1.61 +            sb.append("\n");
    1.62 +            dumpStrackTrace(A, sb);
    1.63 +            dumpStrackTrace(B, sb);
    1.64 +            dumpStrackTrace(C, sb);
    1.65 +
    1.66 +            fail(sb.toString());
    1.67 +        }
    1.68      }
    1.69  
    1.70      
    1.71 @@ -918,6 +933,24 @@
    1.72      public void testThrowingRuntimeExceptionInSpecialCase() throws Exception {
    1.73          exceptionsReporting(new RuntimeException());
    1.74      } 
    1.75 +
    1.76 +    private void dumpStrackTrace(Thread thread, StringBuffer sb) throws IllegalAccessException, InvocationTargetException {
    1.77 +        sb.append("StackTrace for thread: " + thread.getName() + "\n");
    1.78 +
    1.79 +        StackTraceElement[] arr;
    1.80 +        try {
    1.81 +            Method m = Thread.class.getDeclaredMethod("getStackTrace", new Class[0]);
    1.82 +            arr = (StackTraceElement[])m.invoke(thread, new Object[0]);
    1.83 +        } catch (NoSuchMethodException ex) {
    1.84 +            // no such method on 1.4
    1.85 +            return;
    1.86 +        }
    1.87 +
    1.88 +        for (int i = 0; i < arr.length; i++) {
    1.89 +            sb.append(arr[i].toString());
    1.90 +            sb.append("\n");
    1.91 +        }
    1.92 +    }
    1.93      
    1.94      private class ReadWriteChecking implements Runnable {
    1.95          public Boolean read;