--- jsr166/src/test/tck/JSR166TestCase.java 2003/09/14 20:42:40 1.1
+++ jsr166/src/test/tck/JSR166TestCase.java 2003/09/20 18:20:08 1.3
@@ -41,9 +41,8 @@ import java.io.*;
* methods, etc) needed to reach a timeout point. Similarly, a SMALL
* is always discriminable as larger than SHORT and smaller than
* MEDIUM. And so on. These constants are set to conservative values,
- * (100, 500, 1000, 5000 MS) but even so, if there is ever any doubt,
- * they can all be increased in one spot to rerun tests on slower
- * platforms
+ * but even so, if there is ever any doubt, they can all be increased
+ * in one spot to rerun tests on slower platforms
*
*
All threads generated must be joined inside each test case
* method (or fail to do so) before returning from the
@@ -54,6 +53,31 @@ import java.io.*;
*/
public class JSR166TestCase extends TestCase {
+ public static long SHORT_DELAY_MS;
+ public static long SMALL_DELAY_MS;
+ public static long MEDIUM_DELAY_MS;
+ public static long LONG_DELAY_MS;
+
+
+ /**
+ * Return the shortest timed delay. This could
+ * be reimplmented to use for example a Property.
+ */
+ protected long getShortDelay() {
+ return 50;
+ }
+
+
+ /**
+ * Set delays as multiples fo SHORT_DELAY.
+ */
+ protected void setDelays() {
+ SHORT_DELAY_MS = getShortDelay();
+ SMALL_DELAY_MS = SHORT_DELAY_MS * 5;
+ MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10;
+ LONG_DELAY_MS = SHORT_DELAY_MS * 50;
+ }
+
/**
* Flag set true if any threadAssert methods fail
*/
@@ -63,6 +87,7 @@ public class JSR166TestCase extends Test
* Initialize test to indicat that no thread assertions have failed
*/
public void setUp() {
+ setDelays();
threadFailed = false;
}
@@ -109,6 +134,17 @@ public class JSR166TestCase extends Test
}
}
+ public void threadShouldThrow() {
+ threadFailed = true;
+ fail("should throw exception");
+ }
+
+ public void threadUnexpectedException() {
+ threadFailed = true;
+ fail("Unexpected exception");
+ }
+
+
/**
* Wait out termination of a thread pool or fail doing so
*/
@@ -117,14 +153,18 @@ public class JSR166TestCase extends Test
exec.shutdown();
assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
} catch(InterruptedException ie) {
- fail("unexpected exception");
+ fail("Unexpected exception");
}
}
- public static final long SHORT_DELAY_MS = 100;
- public static final long SMALL_DELAY_MS = 500;
- public static final long MEDIUM_DELAY_MS = 1000;
- public static final long LONG_DELAY_MS = 5000;
+
+ public void shouldThrow() {
+ fail("Should throw exception");
+ }
+
+ public void unexpectedException() {
+ fail("Unexpected exception");
+ }
/**
@@ -168,7 +208,7 @@ public class JSR166TestCase extends Test
Thread.sleep(SHORT_DELAY_MS);
}
catch(Exception e) {
- threadFail("unexpectedException");
+ threadUnexpectedException();
}
}
}
@@ -177,7 +217,7 @@ public class JSR166TestCase extends Test
public void run() {
try {
Thread.sleep(SHORT_DELAY_MS);
- threadFail("should throw IE");
+ threadShouldThrow();
}
catch(InterruptedException success) {
}
@@ -190,7 +230,7 @@ public class JSR166TestCase extends Test
Thread.sleep(SMALL_DELAY_MS);
}
catch(Exception e) {
- threadFail("unexpectedException");
+ threadUnexpectedException();
}
}
}
@@ -201,7 +241,7 @@ public class JSR166TestCase extends Test
Thread.sleep(SMALL_DELAY_MS);
}
catch(Exception e) {
- threadFail("unexpectedException");
+ threadUnexpectedException();
}
return Boolean.TRUE;
}
@@ -211,7 +251,7 @@ public class JSR166TestCase extends Test
public void run() {
try {
Thread.sleep(SMALL_DELAY_MS);
- threadFail("should throw IE");
+ threadShouldThrow();
}
catch(InterruptedException success) {
}
@@ -225,7 +265,7 @@ public class JSR166TestCase extends Test
Thread.sleep(MEDIUM_DELAY_MS);
}
catch(Exception e) {
- threadFail("unexpectedException");
+ threadUnexpectedException();
}
}
}
@@ -234,7 +274,7 @@ public class JSR166TestCase extends Test
public void run() {
try {
Thread.sleep(MEDIUM_DELAY_MS);
- threadFail("should throw IE");
+ threadShouldThrow();
}
catch(InterruptedException success) {
}