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.29 by dl, Sat Oct 1 17:05:38 2005 UTC vs.
Revision 1.35 by jsr166, Mon Aug 3 19:07:51 2009 UTC

# Line 108 | Line 108 | public class JSR166TestCase extends Test
108      public static Test suite ( ) {
109          TestSuite suite = new TestSuite("JSR166 Unit Tests");
110  
111 +        suite.addTest(new TestSuite(ForkJoinPoolTest.class));
112 +        suite.addTest(new TestSuite(ForkJoinTaskTest.class));
113 +        suite.addTest(new TestSuite(RecursiveActionTest.class));
114 +        suite.addTest(new TestSuite(RecursiveTaskTest.class));
115 +        suite.addTest(new TestSuite(LinkedTransferQueueTest.class));
116 +        suite.addTest(new TestSuite(PhaserTest.class));
117 +        suite.addTest(new TestSuite(ThreadLocalRandomTest.class));
118          suite.addTest(new TestSuite(AbstractExecutorServiceTest.class));
119          suite.addTest(new TestSuite(AbstractQueueTest.class));
120          suite.addTest(new TestSuite(AbstractQueuedSynchronizerTest.class));
# Line 281 | Line 288 | public class JSR166TestCase extends Test
288       * threadFail with message "should throw exception"
289       */
290      public void threadShouldThrow() {
291 <        threadFailed = true;
292 <        fail("should throw exception");
291 >        try {
292 >            threadFailed = true;
293 >            fail("should throw exception");
294 >        } catch (AssertionFailedError e) {
295 >            e.printStackTrace();
296 >            throw e;
297 >        }
298      }
299  
300      /**
# Line 293 | Line 305 | public class JSR166TestCase extends Test
305          fail("Unexpected exception");
306      }
307  
308 +    /**
309 +     * threadFail with message "Unexpected exception", with argument
310 +     */
311 +    public void threadUnexpectedException(Throwable ex) {
312 +        threadFailed = true;
313 +        ex.printStackTrace();
314 +        fail("Unexpected exception: " + ex);
315 +    }
316  
317      /**
318       * Wait out termination of a thread pool or fail doing so
# Line 301 | Line 321 | public class JSR166TestCase extends Test
321          try {
322              exec.shutdown();
323              assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
324 <        } catch(SecurityException ok) {
324 >        } catch (SecurityException ok) {
325              // Allowed in case test doesn't have privs
326 <        } catch(InterruptedException ie) {
326 >        } catch (InterruptedException ie) {
327              fail("Unexpected exception");
328          }
329      }
# Line 346 | Line 366 | public class JSR166TestCase extends Test
366      static final Integer m3  = new Integer(-3);
367      static final Integer m4 = new Integer(-4);
368      static final Integer m5 = new Integer(-5);
369 +    static final Integer m6 = new Integer(-6);
370      static final Integer m10 = new Integer(-10);
371  
372  
# Line 373 | Line 394 | public class JSR166TestCase extends Test
394  
395      // Some convenient Runnable classes
396  
397 +    abstract class CheckedRunnable implements Runnable {
398 +        abstract void realRun() throws Throwable;
399 +
400 +        public final void run() {
401 +            try {
402 +                realRun();
403 +            } catch (Throwable t) {
404 +                threadUnexpectedException(t);
405 +            }
406 +        }
407 +    }
408 +
409 +    abstract class CheckedInterruptedRunnable implements Runnable {
410 +        abstract void realRun() throws Throwable;
411 +
412 +        public final void run() {
413 +            try {
414 +                realRun();
415 +                threadShouldThrow();
416 +            } catch (InterruptedException success) {
417 +            } catch (Throwable t) {
418 +                threadUnexpectedException(t);
419 +            }
420 +        }
421 +    }
422 +
423 +    abstract class CheckedCallable<T> implements Callable<T> {
424 +        abstract T realCall() throws Throwable;
425 +
426 +        public final T call() {
427 +            try {
428 +                return realCall();
429 +            } catch (Throwable t) {
430 +                threadUnexpectedException(t);
431 +                return null;
432 +            }
433 +        }
434 +    }
435 +
436      static class NoOpRunnable implements Runnable {
437          public void run() {}
438      }
# Line 395 | Line 455 | public class JSR166TestCase extends Test
455          public Integer call() { return one; }
456      }
457  
458 <    class ShortRunnable implements Runnable {
459 <        public void run() {
460 <            try {
401 <                Thread.sleep(SHORT_DELAY_MS);
402 <            }
403 <            catch(Exception e) {
404 <                threadUnexpectedException();
405 <            }
458 >    class ShortRunnable extends CheckedRunnable {
459 >        void realRun() throws Throwable {
460 >            Thread.sleep(SHORT_DELAY_MS);
461          }
462      }
463  
464 <    class ShortInterruptedRunnable implements Runnable {
465 <        public void run() {
466 <            try {
412 <                Thread.sleep(SHORT_DELAY_MS);
413 <                threadShouldThrow();
414 <            }
415 <            catch(InterruptedException success) {
416 <            }
464 >    class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
465 >        void realRun() throws InterruptedException {
466 >            Thread.sleep(SHORT_DELAY_MS);
467          }
468      }
469  
470 <    class SmallRunnable implements Runnable {
471 <        public void run() {
472 <            try {
423 <                Thread.sleep(SMALL_DELAY_MS);
424 <            }
425 <            catch(Exception e) {
426 <                threadUnexpectedException();
427 <            }
470 >    class SmallRunnable extends CheckedRunnable {
471 >        void realRun() throws Throwable {
472 >            Thread.sleep(SMALL_DELAY_MS);
473          }
474      }
475  
476 <    class SmallPossiblyInterruptedRunnable implements Runnable {
477 <        public void run() {
476 >    class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
477 >        void realRun() {
478              try {
479                  Thread.sleep(SMALL_DELAY_MS);
480              }
481 <            catch(Exception e) {
481 >            catch (InterruptedException ok) {
482              }
483          }
484      }
485  
486 <    class SmallCallable implements Callable {
487 <        public Object call() {
488 <            try {
444 <                Thread.sleep(SMALL_DELAY_MS);
445 <            }
446 <            catch(Exception e) {
447 <                threadUnexpectedException();
448 <            }
486 >    class SmallCallable extends CheckedCallable {
487 >        Object realCall() throws Throwable {
488 >            Thread.sleep(SMALL_DELAY_MS);
489              return Boolean.TRUE;
490          }
491      }
492  
493 <    class SmallInterruptedRunnable implements Runnable {
494 <        public void run() {
495 <            try {
456 <                Thread.sleep(SMALL_DELAY_MS);
457 <                threadShouldThrow();
458 <            }
459 <            catch(InterruptedException success) {
460 <            }
493 >    class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
494 >        void realRun() throws InterruptedException {
495 >            Thread.sleep(SMALL_DELAY_MS);
496          }
497      }
498  
499 <
500 <    class MediumRunnable implements Runnable {
501 <        public void run() {
467 <            try {
468 <                Thread.sleep(MEDIUM_DELAY_MS);
469 <            }
470 <            catch(Exception e) {
471 <                threadUnexpectedException();
472 <            }
499 >    class MediumRunnable extends CheckedRunnable {
500 >        void realRun() throws Throwable {
501 >            Thread.sleep(MEDIUM_DELAY_MS);
502          }
503      }
504  
505 <    class MediumInterruptedRunnable implements Runnable {
506 <        public void run() {
507 <            try {
479 <                Thread.sleep(MEDIUM_DELAY_MS);
480 <                threadShouldThrow();
481 <            }
482 <            catch(InterruptedException success) {
483 <            }
505 >    class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
506 >        void realRun() throws InterruptedException {
507 >            Thread.sleep(MEDIUM_DELAY_MS);
508          }
509      }
510  
511 <    class MediumPossiblyInterruptedRunnable implements Runnable {
512 <        public void run() {
511 >    class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
512 >        void realRun() {
513              try {
514                  Thread.sleep(MEDIUM_DELAY_MS);
515              }
516 <            catch(InterruptedException success) {
516 >            catch (InterruptedException ok) {
517              }
518          }
519      }
520  
521 <    class LongPossiblyInterruptedRunnable implements Runnable {
522 <        public void run() {
521 >    class LongPossiblyInterruptedRunnable extends CheckedRunnable {
522 >        void realRun() {
523              try {
524                  Thread.sleep(LONG_DELAY_MS);
525              }
526 <            catch(InterruptedException success) {
526 >            catch (InterruptedException ok) {
527              }
528          }
529      }
# Line 507 | Line 531 | public class JSR166TestCase extends Test
531      /**
532       * For use as ThreadFactory in constructors
533       */
534 <    static class SimpleThreadFactory implements ThreadFactory{
535 <        public Thread newThread(Runnable r){
534 >    static class SimpleThreadFactory implements ThreadFactory {
535 >        public Thread newThread(Runnable r) {
536              return new Thread(r);
537          }
538      }
# Line 519 | Line 543 | public class JSR166TestCase extends Test
543              try {
544                  Thread.sleep(SMALL_DELAY_MS);
545                  done = true;
546 <            } catch(Exception e){
546 >            } catch (Exception e) {
547              }
548          }
549      }
# Line 530 | Line 554 | public class JSR166TestCase extends Test
554              try {
555                  Thread.sleep(MEDIUM_DELAY_MS);
556                  done = true;
557 <            } catch(Exception e){
557 >            } catch (Exception e) {
558              }
559          }
560      }
# Line 541 | Line 565 | public class JSR166TestCase extends Test
565              try {
566                  Thread.sleep(LONG_DELAY_MS);
567                  done = true;
568 <            } catch(Exception e){
568 >            } catch (Exception e) {
569              }
570          }
571      }
# Line 559 | Line 583 | public class JSR166TestCase extends Test
583              try {
584                  Thread.sleep(SMALL_DELAY_MS);
585                  done = true;
586 <            } catch(Exception e){
586 >            } catch (Exception e) {
587              }
588              return Boolean.TRUE;
589          }
# Line 569 | Line 593 | public class JSR166TestCase extends Test
593      /**
594       * For use as RejectedExecutionHandler in constructors
595       */
596 <    static class NoOpREHandler implements RejectedExecutionHandler{
597 <        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
596 >    static class NoOpREHandler implements RejectedExecutionHandler {
597 >        public void rejectedExecution(Runnable r,
598 >                                      ThreadPoolExecutor executor) {}
599      }
600  
576
601   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines