1.1 --- a/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java Thu Jul 14 12:56:31 2005 +0000
1.2 +++ b/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java Fri Jul 15 14:10:32 2005 +0000
1.3 @@ -25,10 +25,17 @@
1.4 System.setProperty("org.openide.util.Lookup", "org.openide.util.RequestProcessorTest$Lkp");
1.5 }
1.6
1.7 + private ErrorManager log;
1.8 +
1.9 public RequestProcessorTest(java.lang.String testName) {
1.10 super(testName);
1.11 }
1.12
1.13 + protected void setUp () throws Exception {
1.14 + super.setUp();
1.15 +
1.16 + log = ErrorManager.getDefault().getInstance(getName());
1.17 + }
1.18
1.19 protected void runTest() throws Throwable {
1.20 assertNotNull ("ErrManager has to be in lookup", org.openide.util.Lookup.getDefault ().lookup (ErrManager.class));
1.21 @@ -38,7 +45,7 @@
1.22 super.runTest();
1.23 } catch (Throwable ex) {
1.24 throw new junit.framework.AssertionFailedError (
1.25 - ErrManager.messages.toString()
1.26 + ex.getMessage() + "\n" + ErrManager.messages.toString()
1.27 ).initCause(ex);
1.28 }
1.29 }
1.30 @@ -693,49 +700,72 @@
1.31 RequestProcessor rp = new RequestProcessor ("Cancellable", 1, true);
1.32
1.33 class R implements Runnable {
1.34 + private String name;
1.35 +
1.36 public boolean checkBefore;
1.37 public boolean checkAfter;
1.38 public boolean interrupted;
1.39
1.40 + public R (String n) {
1.41 + this.name = n;
1.42 + }
1.43 +
1.44 public synchronized void run () {
1.45 checkBefore = Thread.interrupted();
1.46
1.47 + log.log("in runnable " + name + " check before: " + checkBefore);
1.48 +
1.49 notifyAll ();
1.50 +
1.51 + log.log("in runnable " + name + " after notify");
1.52
1.53 try {
1.54 wait ();
1.55 + log.log("in runnable " + name + " after wait, not interrupted");
1.56 interrupted = false;
1.57 } catch (InterruptedException ex) {
1.58 interrupted = true;
1.59 + log.log("in runnable " + name + " after wait, interrupted");
1.60 }
1.61
1.62 notifyAll ();
1.63
1.64 + log.log("in runnable " + name + " after notifyAll");
1.65 +
1.66 try {
1.67 wait ();
1.68 + log.log("in runnable " + name + " after second wait, not interrupted");
1.69 } catch (InterruptedException ex) {
1.70 + log.log("in runnable " + name + " after second wait, interrupted");
1.71 }
1.72
1.73 checkAfter = Thread.interrupted();
1.74 + log.log("in runnable " + name + " checkAfter: " + checkAfter);
1.75
1.76 notifyAll ();
1.77 }
1.78 }
1.79
1.80 - R r = new R ();
1.81 + R r = new R ("First");
1.82 RequestProcessor.Task t;
1.83 synchronized (r) {
1.84 t = rp.post (r);
1.85 r.wait ();
1.86 assertTrue ("The task is already running", !t.cancel ());
1.87 + log.log("Main checkpoint1");
1.88 r.wait ();
1.89 + log.log("Main checkpoint2");
1.90 r.notifyAll ();
1.91 + log.log("Main checkpoint3");
1.92 r.wait ();
1.93 + log.log("Main checkpoint4");
1.94 assertTrue ("The task has been interrupted", r.interrupted);
1.95 assertTrue ("Not before", !r.checkBefore);
1.96 assertTrue ("Not after - as the notification was thru InterruptedException", !r.checkAfter);
1.97 }
1.98 + log.log("Main checkpoint5");
1.99 t.waitFinished();
1.100 + log.log("Main checkpoint6");
1.101 /*
1.102 try {
1.103 assertGC("no", new java.lang.ref.WeakReference(this));
1.104 @@ -745,20 +775,27 @@
1.105 */
1.106
1.107 // interrupt after the task has finished
1.108 - r = new R ();
1.109 + r = new R ("Second");
1.110 synchronized (r) {
1.111 t = rp.post (r);
1.112 + log.log("Second checkpoint1");
1.113 r.wait ();
1.114 r.notifyAll ();
1.115 + log.log("Second checkpoint2");
1.116 r.wait ();
1.117 + log.log("Second checkpoint3");
1.118 assertTrue ("The task is already running", !t.cancel ());
1.119 + log.log("Second checkpoint4");
1.120 r.notifyAll ();
1.121 + log.log("Second checkpoint5");
1.122 r.wait ();
1.123 assertTrue ("The task has not been interrupted by exception", !r.interrupted);
1.124 assertTrue ("Not interupted before", !r.checkBefore);
1.125 assertTrue ("But interupted after", r.checkAfter);
1.126 }
1.127 + log.log("Second checkpoint6");
1.128 t.waitFinished();
1.129 + log.log("Second checkpoint7");
1.130 }
1.131
1.132 public void testCancelDoesNotInterruptTheRunningThread () throws Exception {
1.133 @@ -1136,7 +1173,8 @@
1.134
1.135 public org.openide.ErrorManager getInstance (String name) {
1.136 if (
1.137 - name.startsWith ("org.openide.util.RequestProcessor")
1.138 + name.startsWith ("org.openide.util.RequestProcessor") ||
1.139 + name.startsWith("test")
1.140 ) {
1.141 return new ErrManager ('[' + name + ']');
1.142 } else {