harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r584744 - in /harmony/enhanced/drlvm/trunk/src/test/regression/H3256: InterruptTimedWaitingTest.java TestInterruptTimedWaiting.java run.test.xml
Date Mon, 15 Oct 2007 11:30:36 GMT
Author: varlax
Date: Mon Oct 15 04:30:35 2007
New Revision: 584744

URL: http://svn.apache.org/viewvc?rev=584744&view=rev
Log:
Fixed reg test for HARMONY-3256 violating framework conventions.

Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3256/InterruptTimedWaitingTest.java
    harmony/enhanced/drlvm/trunk/src/test/regression/H3256/run.test.xml
Removed:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3256/TestInterruptTimedWaiting.java

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3256/InterruptTimedWaitingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3256/InterruptTimedWaitingTest.java?rev=584744&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3256/InterruptTimedWaitingTest.java
(added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3256/InterruptTimedWaitingTest.java
Mon Oct 15 04:30:35 2007
@@ -0,0 +1,90 @@
+package org.apache.harmony.drlvm.tests.regression.h3256;
+
+public class InterruptTimedWaitingTest {
+
+	Object lock = new Object();
+	int threadCount = 100;
+	int THREAD_WAIT_TIME = 10000;
+	int WAIT_CONDITION_TIME = 2000;
+	int SLEEP_TIME = 100;
+	int loopCountBegin = WAIT_CONDITION_TIME / SLEEP_TIME;
+	int loopCount;
+	int waitedTime;
+
+	class ThreadWaiting extends Thread {
+		volatile boolean exceptionReceived = false;
+		volatile boolean working = false;
+
+		public void run () {
+			synchronized (lock) {
+				this.working = true;
+				lock.notify();
+			}
+			synchronized (this) {
+				try {
+					this.wait(THREAD_WAIT_TIME);
+				} catch (InterruptedException e) {
+					exceptionReceived = true;
+				}
+			}
+		}
+	}
+
+	public void testInterrupt_Waiting() {
+		for (int i = 0; i < threadCount; i++) {
+			ThreadWaiting t = new ThreadWaiting();
+			try {
+				synchronized (lock) {
+					t.start();
+					while (!t.working) {
+						lock.wait();
+					}
+				}
+			} catch (InterruptedException e) {
+					e.printStackTrace();
+			}
+			
+			// wait for Thread.State.TIMED_WAITING
+			Thread.State ts = t.getState();
+			loopCount = loopCountBegin;
+			while ((ts != Thread.State.TIMED_WAITING) && (loopCount-- > 0)) {
+				ts = t.getState();
+				try {
+					Thread.sleep(SLEEP_TIME);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+
+			// interrupt the thread
+			t.interrupt();
+
+			// wait for InteruptedException
+			loopCount = loopCountBegin;
+			while (!t.exceptionReceived && (loopCount-- > 0)) {
+				try {
+					Thread.sleep(SLEEP_TIME);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+			waitedTime = (loopCountBegin - loopCount) * SLEEP_TIME;
+     		System.out.println(i + " exception waited for " + waitedTime + " ms");
+
+			// check for exception received
+			if (loopCount < 0) {
+				System.out.println(i + " FAILED: waiting thread has not received the InterruptedException");
+				System.exit(-1);
+			}
+			// check for interrupted status cleared
+			if (t.isInterrupted()) {
+				System.out.println(i + " FAILED: interrupt status has not been cleared");
+				System.exit(-2);
+			}
+		}
+	}
+
+	public static void main(String args[]) {
+		new InterruptTimedWaitingTest().testInterrupt_Waiting();
+	}
+}
\ No newline at end of file

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3256/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3256/run.test.xml?rev=584744&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3256/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3256/run.test.xml Mon Oct 15 04:30:35
2007
@@ -0,0 +1,7 @@
+<project name="RUN HARMONY-3256 Regression Test">
+    <target name="run-test">
+        <run-pjava-test
+            test="org.apache.harmony.drlvm.tests.regression.h3256.InterruptTimedWaitingTest"/>
+    </target>
+</project>
+



Mime
View raw message