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.32 by dl, Fri Jul 31 23:02:49 2009 UTC vs.
Revision 1.35 by jsr166, Mon Aug 3 19:07:51 2009 UTC

# Line 286 | Line 286 | public class JSR166TestCase extends Test
286  
287      /**
288       * threadFail with message "should throw exception"
289 <     */
289 >     */
290      public void threadShouldThrow() {
291 <       try {
292 <           threadFailed = true;
293 <           fail("should throw exception");
294 <       } catch (AssertionFailedError e) {
295 <           e.printStackTrace();
296 <           throw e;
297 <       }
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 321 | 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 394 | 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 416 | 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 {
422 <                Thread.sleep(SHORT_DELAY_MS);
423 <            }
424 <            catch(Exception e) {
425 <                threadUnexpectedException(e);
426 <            }
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 {
433 <                Thread.sleep(SHORT_DELAY_MS);
434 <                threadShouldThrow();
435 <            }
436 <            catch(InterruptedException success) {
437 <            }
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 {
444 <                Thread.sleep(SMALL_DELAY_MS);
445 <            }
446 <            catch(Exception e) {
447 <                threadUnexpectedException(e);
448 <            }
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 {
465 <                Thread.sleep(SMALL_DELAY_MS);
466 <            }
467 <            catch(Exception e) {
468 <                threadUnexpectedException(e);
469 <            }
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 {
477 <                Thread.sleep(SMALL_DELAY_MS);
478 <                threadShouldThrow();
479 <            }
480 <            catch(InterruptedException success) {
481 <            }
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() {
488 <            try {
489 <                Thread.sleep(MEDIUM_DELAY_MS);
490 <            }
491 <            catch(Exception e) {
492 <                threadUnexpectedException(e);
493 <            }
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 {
500 <                Thread.sleep(MEDIUM_DELAY_MS);
501 <                threadShouldThrow();
502 <            }
503 <            catch(InterruptedException success) {
504 <            }
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 528 | 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 540 | 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 551 | 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 562 | 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 580 | 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 590 | 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  
597
601   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines