You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by va...@apache.org on 2007/01/31 07:16:39 UTC

svn commit: r501742 - /harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/ThreadTest.java

Author: varlax
Date: Tue Jan 30 22:16:38 2007
New Revision: 501742

URL: http://svn.apache.org/viewvc?view=rev&rev=501742
Log:
Applied HARMONY-2126 [drlvm] thread interrupt regression test

Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/ThreadTest.java

Modified: harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/ThreadTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/ThreadTest.java?view=diff&rev=501742&r1=501741&r2=501742
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/ThreadTest.java (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/ThreadTest.java Tue Jan 30 22:16:38 2007
@@ -15,11 +15,6 @@
  *  limitations under the License.
  */
 
-/**
- * @author Roman S. Bushmanov
- * @version $Revision$
- */
-
 package java.lang;
 
 import junit.framework.TestCase;
@@ -1487,6 +1482,73 @@
         }
         assertFalse("interrupt status has not been cleared", 
                 t.isInterrupted());
+    }
+
+    static final int COUNT = 100;
+    volatile int base;
+    
+    /**
+     * Check that interrupt and notify happen exactly once for each
+     * <code>notify()</code> and <code>interrupt()</code> call.
+     */
+    public void testInterrupt_Staging() {
+        ThreadStaging t = new ThreadStaging();
+
+        base = 0;
+        t.start();
+
+        try {
+            for (base = 0; base < COUNT; ) {
+                synchronized (t) {
+                    t.waitStage("notify");
+                    t.notify();
+
+                    t.waitStage("interrupt");
+                    t.interrupt();
+                }
+            }
+        }  catch (InterruptedException e) {
+            fail("Unexpected exception: " + e);
+        }
+    }
+
+    private class ThreadStaging extends Thread {
+        static final long TIMEOUT = 100;
+        int stage;
+        
+        public void run() {
+            for (stage = 0; stage < COUNT; ) {
+
+                try {
+                    waitBase();
+                } catch (InterruptedException e) {
+                    fail("Unexpected exception: " + e);
+                }
+                assertEquals("Stages are not synchronized after interrupt", stage, base);
+
+                try {
+                    waitBase();
+                    fail("The thread should be interrupted");
+                } catch (InterruptedException e) {
+                    assertEquals("Stages are not synchronized after interrupt", stage, base);
+                    continue;
+                }
+                fail("The thread should be interrupted by (InterruptedException");
+            }
+        }
+
+        public synchronized void waitStage(String stageName) throws InterruptedException {
+            for (int i = 0; (base == stage) && (i < COUNT); i++) {
+                wait(TIMEOUT);
+            }
+            assertEquals("waitFor " + stageName + ": stages are not synchronized before", stage, ++base);
+        }
+
+        synchronized void waitBase() throws InterruptedException {
+            stage++;
+            notify();
+            wait(TIMEOUT);
+        }
     }
 
     /**