ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.30 by dl, Thu Apr 20 20:35:00 2006 UTC vs.
Revision 1.36 by jsr166, Mon Aug 3 22:08:45 2009 UTC

# Line 9 | Line 9
9   import junit.framework.*;
10   import java.util.*;
11   import java.util.concurrent.*;
12 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
13   import java.io.*;
14   import java.security.*;
15  
# Line 108 | Line 109 | public class JSR166TestCase extends Test
109      public static Test suite ( ) {
110          TestSuite suite = new TestSuite("JSR166 Unit Tests");
111  
112 +        suite.addTest(new TestSuite(ForkJoinPoolTest.class));
113 +        suite.addTest(new TestSuite(ForkJoinTaskTest.class));
114 +        suite.addTest(new TestSuite(RecursiveActionTest.class));
115 +        suite.addTest(new TestSuite(RecursiveTaskTest.class));
116 +        suite.addTest(new TestSuite(LinkedTransferQueueTest.class));
117 +        suite.addTest(new TestSuite(PhaserTest.class));
118 +        suite.addTest(new TestSuite(ThreadLocalRandomTest.class));
119          suite.addTest(new TestSuite(AbstractExecutorServiceTest.class));
120          suite.addTest(new TestSuite(AbstractQueueTest.class));
121          suite.addTest(new TestSuite(AbstractQueuedSynchronizerTest.class));
# Line 281 | Line 289 | public class JSR166TestCase extends Test
289       * threadFail with message "should throw exception"
290       */
291      public void threadShouldThrow() {
292 <        threadFailed = true;
293 <        fail("should throw exception");
292 >        try {
293 >            threadFailed = true;
294 >            fail("should throw exception");
295 >        } catch (AssertionFailedError e) {
296 >            e.printStackTrace();
297 >            throw e;
298 >        }
299      }
300  
301      /**
# Line 293 | Line 306 | public class JSR166TestCase extends Test
306          fail("Unexpected exception");
307      }
308  
309 +    /**
310 +     * threadFail with message "Unexpected exception", with argument
311 +     */
312 +    public void threadUnexpectedException(Throwable ex) {
313 +        threadFailed = true;
314 +        ex.printStackTrace();
315 +        fail("Unexpected exception: " + ex);
316 +    }
317  
318      /**
319       * Wait out termination of a thread pool or fail doing so
# Line 300 | Line 321 | public class JSR166TestCase extends Test
321      public void joinPool(ExecutorService exec) {
322          try {
323              exec.shutdown();
324 <            assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
325 <        } catch(SecurityException ok) {
324 >            assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
325 >        } catch (SecurityException ok) {
326              // Allowed in case test doesn't have privs
327 <        } catch(InterruptedException ie) {
327 >        } catch (InterruptedException ie) {
328              fail("Unexpected exception");
329          }
330      }
# Line 323 | Line 344 | public class JSR166TestCase extends Test
344          fail("Unexpected exception");
345      }
346  
347 +    /**
348 +     * fail with message "Unexpected exception", with argument
349 +     */
350 +    public void unexpectedException(Throwable ex) {
351 +        ex.printStackTrace();
352 +        fail("Unexpected exception: " + ex);
353 +    }
354 +
355  
356      /**
357       * The number of elements to place in collections, arrays, etc.
# Line 374 | Line 403 | public class JSR166TestCase extends Test
403  
404      // Some convenient Runnable classes
405  
406 +    abstract class CheckedRunnable implements Runnable {
407 +        abstract void realRun() throws Throwable;
408 +
409 +        public final void run() {
410 +            try {
411 +                realRun();
412 +            } catch (Throwable t) {
413 +                threadUnexpectedException(t);
414 +            }
415 +        }
416 +    }
417 +
418 +    abstract class CheckedInterruptedRunnable implements Runnable {
419 +        abstract void realRun() throws Throwable;
420 +
421 +        public final void run() {
422 +            try {
423 +                realRun();
424 +                threadShouldThrow();
425 +            } catch (InterruptedException success) {
426 +            } catch (Throwable t) {
427 +                threadUnexpectedException(t);
428 +            }
429 +        }
430 +    }
431 +
432 +    abstract class CheckedCallable<T> implements Callable<T> {
433 +        abstract T realCall() throws Throwable;
434 +
435 +        public final T call() {
436 +            try {
437 +                return realCall();
438 +            } catch (Throwable t) {
439 +                threadUnexpectedException(t);
440 +                return null;
441 +            }
442 +        }
443 +    }
444 +
445      static class NoOpRunnable implements Runnable {
446          public void run() {}
447      }
# Line 396 | Line 464 | public class JSR166TestCase extends Test
464          public Integer call() { return one; }
465      }
466  
467 <    class ShortRunnable implements Runnable {
468 <        public void run() {
469 <            try {
402 <                Thread.sleep(SHORT_DELAY_MS);
403 <            }
404 <            catch(Exception e) {
405 <                threadUnexpectedException();
406 <            }
467 >    class ShortRunnable extends CheckedRunnable {
468 >        void realRun() throws Throwable {
469 >            Thread.sleep(SHORT_DELAY_MS);
470          }
471      }
472  
473 <    class ShortInterruptedRunnable implements Runnable {
474 <        public void run() {
475 <            try {
413 <                Thread.sleep(SHORT_DELAY_MS);
414 <                threadShouldThrow();
415 <            }
416 <            catch(InterruptedException success) {
417 <            }
473 >    class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
474 >        void realRun() throws InterruptedException {
475 >            Thread.sleep(SHORT_DELAY_MS);
476          }
477      }
478  
479 <    class SmallRunnable implements Runnable {
480 <        public void run() {
481 <            try {
424 <                Thread.sleep(SMALL_DELAY_MS);
425 <            }
426 <            catch(Exception e) {
427 <                threadUnexpectedException();
428 <            }
479 >    class SmallRunnable extends CheckedRunnable {
480 >        void realRun() throws Throwable {
481 >            Thread.sleep(SMALL_DELAY_MS);
482          }
483      }
484  
485 <    class SmallPossiblyInterruptedRunnable implements Runnable {
486 <        public void run() {
485 >    class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
486 >        void realRun() {
487              try {
488                  Thread.sleep(SMALL_DELAY_MS);
489              }
490 <            catch(Exception e) {
490 >            catch (InterruptedException ok) {
491              }
492          }
493      }
494  
495 <    class SmallCallable implements Callable {
496 <        public Object call() {
497 <            try {
445 <                Thread.sleep(SMALL_DELAY_MS);
446 <            }
447 <            catch(Exception e) {
448 <                threadUnexpectedException();
449 <            }
495 >    class SmallCallable extends CheckedCallable {
496 >        Object realCall() throws Throwable {
497 >            Thread.sleep(SMALL_DELAY_MS);
498              return Boolean.TRUE;
499          }
500      }
501  
502 <    class SmallInterruptedRunnable implements Runnable {
503 <        public void run() {
504 <            try {
457 <                Thread.sleep(SMALL_DELAY_MS);
458 <                threadShouldThrow();
459 <            }
460 <            catch(InterruptedException success) {
461 <            }
502 >    class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
503 >        void realRun() throws InterruptedException {
504 >            Thread.sleep(SMALL_DELAY_MS);
505          }
506      }
507  
508 <
509 <    class MediumRunnable implements Runnable {
510 <        public void run() {
468 <            try {
469 <                Thread.sleep(MEDIUM_DELAY_MS);
470 <            }
471 <            catch(Exception e) {
472 <                threadUnexpectedException();
473 <            }
508 >    class MediumRunnable extends CheckedRunnable {
509 >        void realRun() throws Throwable {
510 >            Thread.sleep(MEDIUM_DELAY_MS);
511          }
512      }
513  
514 <    class MediumInterruptedRunnable implements Runnable {
515 <        public void run() {
516 <            try {
480 <                Thread.sleep(MEDIUM_DELAY_MS);
481 <                threadShouldThrow();
482 <            }
483 <            catch(InterruptedException success) {
484 <            }
514 >    class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
515 >        void realRun() throws InterruptedException {
516 >            Thread.sleep(MEDIUM_DELAY_MS);
517          }
518      }
519  
520 <    class MediumPossiblyInterruptedRunnable implements Runnable {
521 <        public void run() {
520 >    class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
521 >        void realRun() {
522              try {
523                  Thread.sleep(MEDIUM_DELAY_MS);
524              }
525 <            catch(InterruptedException success) {
525 >            catch (InterruptedException ok) {
526              }
527          }
528      }
529  
530 <    class LongPossiblyInterruptedRunnable implements Runnable {
531 <        public void run() {
530 >    class LongPossiblyInterruptedRunnable extends CheckedRunnable {
531 >        void realRun() {
532              try {
533                  Thread.sleep(LONG_DELAY_MS);
534              }
535 <            catch(InterruptedException success) {
535 >            catch (InterruptedException ok) {
536              }
537          }
538      }
# Line 508 | Line 540 | public class JSR166TestCase extends Test
540      /**
541       * For use as ThreadFactory in constructors
542       */
543 <    static class SimpleThreadFactory implements ThreadFactory{
544 <        public Thread newThread(Runnable r){
543 >    static class SimpleThreadFactory implements ThreadFactory {
544 >        public Thread newThread(Runnable r) {
545              return new Thread(r);
546          }
547      }
# Line 520 | Line 552 | public class JSR166TestCase extends Test
552              try {
553                  Thread.sleep(SMALL_DELAY_MS);
554                  done = true;
555 <            } catch(Exception e){
555 >            } catch (Exception e) {
556              }
557          }
558      }
# Line 531 | Line 563 | public class JSR166TestCase extends Test
563              try {
564                  Thread.sleep(MEDIUM_DELAY_MS);
565                  done = true;
566 <            } catch(Exception e){
566 >            } catch (Exception e) {
567              }
568          }
569      }
# Line 542 | Line 574 | public class JSR166TestCase extends Test
574              try {
575                  Thread.sleep(LONG_DELAY_MS);
576                  done = true;
577 <            } catch(Exception e){
577 >            } catch (Exception e) {
578              }
579          }
580      }
# Line 560 | Line 592 | public class JSR166TestCase extends Test
592              try {
593                  Thread.sleep(SMALL_DELAY_MS);
594                  done = true;
595 <            } catch(Exception e){
595 >            } catch (Exception e) {
596              }
597              return Boolean.TRUE;
598          }
# Line 570 | Line 602 | public class JSR166TestCase extends Test
602      /**
603       * For use as RejectedExecutionHandler in constructors
604       */
605 <    static class NoOpREHandler implements RejectedExecutionHandler{
606 <        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
605 >    static class NoOpREHandler implements RejectedExecutionHandler {
606 >        public void rejectedExecution(Runnable r,
607 >                                      ThreadPoolExecutor executor) {}
608      }
609  
577
610   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines