Index: vm/tests/kernel/java/lang/ThreadTest.java
===================================================================
--- vm/tests/kernel/java/lang/ThreadTest.java (revision 483769)
+++ vm/tests/kernel/java/lang/ThreadTest.java (working copy)
@@ -16,7 +16,7 @@
*/
/**
- * @author Roman S. Bushmanov
+ * @author Roman S. Bushmanov, Alexei Fedotov
* @version $Revision$
*/
@@ -1489,7 +1489,74 @@
t.isInterrupted());
}
+ static final int COUNT = 100;
+ int base;
+
/**
+ * Check that interrupt and notify happen exactly once for each
+ * notify() and interrupt() 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);
+ }
+ }
+
+ /**
* Verify that the current thread is alive
*/
public void testIsAliveCurrent() {
@@ -1902,4 +1969,5 @@
return;
}
}
-}
\ No newline at end of file
+}
+