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.41 by jsr166, Fri Nov 20 06:27:39 2009 UTC vs.
Revision 1.48 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 195 | Line 195 | public class JSR166TestCase extends Test
195      /**
196       * Sets delays as multiples of SHORT_DELAY.
197       */
198 <    protected  void setDelays() {
198 >    protected void setDelays() {
199          SHORT_DELAY_MS = getShortDelay();
200          SMALL_DELAY_MS = SHORT_DELAY_MS * 5;
201          MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10;
# Line 328 | Line 328 | public class JSR166TestCase extends Test
328          } catch (SecurityException ok) {
329              // Allowed in case test doesn't have privs
330          } catch (InterruptedException ie) {
331 <            fail("Unexpected exception");
331 >            fail("Unexpected InterruptedException");
332          }
333      }
334  
# Line 366 | Line 366 | public class JSR166TestCase extends Test
366      /**
367       * The number of elements to place in collections, arrays, etc.
368       */
369 <    static final int SIZE = 20;
369 >    public static final int SIZE = 20;
370  
371      // Some convenient Integer constants
372  
373 <    static final Integer zero = new Integer(0);
374 <    static final Integer one = new Integer(1);
375 <    static final Integer two = new Integer(2);
376 <    static final Integer three  = new Integer(3);
377 <    static final Integer four  = new Integer(4);
378 <    static final Integer five  = new Integer(5);
379 <    static final Integer six = new Integer(6);
380 <    static final Integer seven = new Integer(7);
381 <    static final Integer eight = new Integer(8);
382 <    static final Integer nine = new Integer(9);
383 <    static final Integer m1  = new Integer(-1);
384 <    static final Integer m2  = new Integer(-2);
385 <    static final Integer m3  = new Integer(-3);
386 <    static final Integer m4 = new Integer(-4);
387 <    static final Integer m5 = new Integer(-5);
388 <    static final Integer m6 = new Integer(-6);
389 <    static final Integer m10 = new Integer(-10);
373 >    public static final Integer zero  = new Integer(0);
374 >    public static final Integer one   = new Integer(1);
375 >    public static final Integer two   = new Integer(2);
376 >    public static final Integer three = new Integer(3);
377 >    public static final Integer four  = new Integer(4);
378 >    public static final Integer five  = new Integer(5);
379 >    public static final Integer six   = new Integer(6);
380 >    public static final Integer seven = new Integer(7);
381 >    public static final Integer eight = new Integer(8);
382 >    public static final Integer nine  = new Integer(9);
383 >    public static final Integer m1  = new Integer(-1);
384 >    public static final Integer m2  = new Integer(-2);
385 >    public static final Integer m3  = new Integer(-3);
386 >    public static final Integer m4  = new Integer(-4);
387 >    public static final Integer m5  = new Integer(-5);
388 >    public static final Integer m6  = new Integer(-6);
389 >    public static final Integer m10 = new Integer(-10);
390  
391  
392      /**
393       * A security policy where new permissions can be dynamically added
394       * or all cleared.
395       */
396 <    static class AdjustablePolicy extends java.security.Policy {
396 >    public static class AdjustablePolicy extends java.security.Policy {
397          Permissions perms = new Permissions();
398          AdjustablePolicy() { }
399          void addPermission(Permission perm) { perms.add(perm); }
400          void clearPermissions() { perms = new Permissions(); }
401 <        public PermissionCollection getPermissions(CodeSource cs) {
402 <            return perms;
403 <        }
404 <        public PermissionCollection getPermissions(ProtectionDomain pd) {
405 <            return perms;
406 <        }
407 <        public boolean implies(ProtectionDomain pd, Permission p) {
408 <            return perms.implies(p);
409 <        }
410 <        public void refresh() {}
401 >        public PermissionCollection getPermissions(CodeSource cs) {
402 >            return perms;
403 >        }
404 >        public PermissionCollection getPermissions(ProtectionDomain pd) {
405 >            return perms;
406 >        }
407 >        public boolean implies(ProtectionDomain pd, Permission p) {
408 >            return perms.implies(p);
409 >        }
410 >        public void refresh() {}
411      }
412  
413      /**
# Line 417 | Line 417 | public class JSR166TestCase extends Test
417      void sleepTillInterrupted(long timeoutMillis) {
418          try {
419              Thread.sleep(timeoutMillis);
420 <        } catch (InterruptedException wakeup) {
421 <        }
420 >        } catch (InterruptedException wakeup) {}
421      }
422  
423      /**
# Line 432 | Line 431 | public class JSR166TestCase extends Test
431  
432      // Some convenient Runnable classes
433  
434 <    abstract class CheckedRunnable implements Runnable {
435 <        abstract void realRun() throws Throwable;
434 >    public abstract class CheckedRunnable implements Runnable {
435 >        protected abstract void realRun() throws Throwable;
436  
437          public final void run() {
438              try {
# Line 444 | Line 443 | public class JSR166TestCase extends Test
443          }
444      }
445  
446 <    abstract class RunnableShouldThrow implements Runnable {
447 <        abstract void realRun() throws Throwable;
446 >    public abstract class RunnableShouldThrow implements Runnable {
447 >        protected abstract void realRun() throws Throwable;
448  
449          final Class<?> exceptionClass;
450  
# Line 457 | Line 456 | public class JSR166TestCase extends Test
456              try {
457                  realRun();
458                  threadShouldThrow(exceptionClass.getSimpleName());
460            } catch (InterruptedException success) {
459              } catch (Throwable t) {
460                  if (! exceptionClass.isInstance(t))
461                      threadUnexpectedException(t);
# Line 465 | Line 463 | public class JSR166TestCase extends Test
463          }
464      }
465  
466 <    abstract class ThreadShouldThrow extends Thread {
467 <        abstract void realRun() throws Throwable;
466 >    public abstract class ThreadShouldThrow extends Thread {
467 >        protected abstract void realRun() throws Throwable;
468  
469          final Class<?> exceptionClass;
470  
# Line 478 | Line 476 | public class JSR166TestCase extends Test
476              try {
477                  realRun();
478                  threadShouldThrow(exceptionClass.getSimpleName());
481            } catch (InterruptedException success) {
479              } catch (Throwable t) {
480                  if (! exceptionClass.isInstance(t))
481                      threadUnexpectedException(t);
# Line 486 | Line 483 | public class JSR166TestCase extends Test
483          }
484      }
485  
486 <    abstract class CheckedInterruptedRunnable implements Runnable {
487 <        abstract void realRun() throws Throwable;
486 >    public abstract class CheckedInterruptedRunnable implements Runnable {
487 >        protected abstract void realRun() throws Throwable;
488  
489          public final void run() {
490              try {
# Line 500 | Line 497 | public class JSR166TestCase extends Test
497          }
498      }
499  
500 <    abstract class CheckedCallable<T> implements Callable<T> {
501 <        abstract T realCall() throws Throwable;
500 >    public abstract class CheckedCallable<T> implements Callable<T> {
501 >        protected abstract T realCall() throws Throwable;
502  
503          public final T call() {
504              try {
# Line 513 | Line 510 | public class JSR166TestCase extends Test
510          }
511      }
512  
513 <    abstract class CheckedInterruptedCallable<T> implements Callable<T> {
514 <        abstract T realCall() throws Throwable;
513 >    public abstract class CheckedInterruptedCallable<T> implements Callable<T> {
514 >        protected abstract T realCall() throws Throwable;
515  
516          public final T call() {
517              try {
# Line 529 | Line 526 | public class JSR166TestCase extends Test
526          }
527      }
528  
529 <    static class NoOpRunnable implements Runnable {
529 >    public static class NoOpRunnable implements Runnable {
530          public void run() {}
531      }
532  
533 <    static class NoOpCallable implements Callable {
533 >    public static class NoOpCallable implements Callable {
534          public Object call() { return Boolean.TRUE; }
535      }
536  
537 <    static final String TEST_STRING = "a test string";
537 >    public static final String TEST_STRING = "a test string";
538  
539 <    static class StringTask implements Callable<String> {
539 >    public static class StringTask implements Callable<String> {
540          public String call() { return TEST_STRING; }
541      }
542  
543 <    static class NPETask implements Callable<String> {
543 >    public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) {
544 >        return new CheckedCallable<String>() {
545 >            public String realCall() {
546 >                try {
547 >                    latch.await();
548 >                } catch (InterruptedException quittingTime) {}
549 >                return TEST_STRING;
550 >            }};
551 >    }
552 >
553 >    public static class NPETask implements Callable<String> {
554          public String call() { throw new NullPointerException(); }
555      }
556  
557 <    static class CallableOne implements Callable<Integer> {
557 >    public static class CallableOne implements Callable<Integer> {
558          public Integer call() { return one; }
559      }
560  
561 <    class ShortRunnable extends CheckedRunnable {
562 <        void realRun() throws Throwable {
561 >    public class ShortRunnable extends CheckedRunnable {
562 >        protected void realRun() throws Throwable {
563              Thread.sleep(SHORT_DELAY_MS);
564          }
565      }
566  
567 <    class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
568 <        void realRun() throws InterruptedException {
567 >    public class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
568 >        protected void realRun() throws InterruptedException {
569              Thread.sleep(SHORT_DELAY_MS);
570          }
571      }
572  
573 <    class SmallRunnable extends CheckedRunnable {
574 <        void realRun() throws Throwable {
573 >    public class SmallRunnable extends CheckedRunnable {
574 >        protected void realRun() throws Throwable {
575              Thread.sleep(SMALL_DELAY_MS);
576          }
577      }
578  
579 <    class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
580 <        void realRun() {
579 >    public class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
580 >        protected void realRun() {
581              try {
582                  Thread.sleep(SMALL_DELAY_MS);
583 <            }
577 <            catch (InterruptedException ok) {
578 <            }
583 >            } catch (InterruptedException ok) {}
584          }
585      }
586  
587 <    class SmallCallable extends CheckedCallable {
588 <        Object realCall() throws Throwable {
587 >    public class SmallCallable extends CheckedCallable {
588 >        protected Object realCall() throws InterruptedException {
589              Thread.sleep(SMALL_DELAY_MS);
590              return Boolean.TRUE;
591          }
592      }
593  
594 <    class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
595 <        void realRun() throws InterruptedException {
594 >    public class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
595 >        protected void realRun() throws InterruptedException {
596              Thread.sleep(SMALL_DELAY_MS);
597          }
598      }
599  
600 <    class MediumRunnable extends CheckedRunnable {
601 <        void realRun() throws Throwable {
600 >    public class MediumRunnable extends CheckedRunnable {
601 >        protected void realRun() throws Throwable {
602              Thread.sleep(MEDIUM_DELAY_MS);
603          }
604      }
605  
606 <    class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
607 <        void realRun() throws InterruptedException {
606 >    public class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
607 >        protected void realRun() throws InterruptedException {
608              Thread.sleep(MEDIUM_DELAY_MS);
609          }
610      }
611  
612 <    class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
613 <        void realRun() {
612 >    public class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
613 >        protected void realRun() {
614              try {
615                  Thread.sleep(MEDIUM_DELAY_MS);
616 <            }
612 <            catch (InterruptedException ok) {
613 <            }
616 >            } catch (InterruptedException ok) {}
617          }
618      }
619  
620 <    class LongPossiblyInterruptedRunnable extends CheckedRunnable {
621 <        void realRun() {
620 >    public class LongPossiblyInterruptedRunnable extends CheckedRunnable {
621 >        protected void realRun() {
622              try {
623                  Thread.sleep(LONG_DELAY_MS);
624 <            }
622 <            catch (InterruptedException ok) {
623 <            }
624 >            } catch (InterruptedException ok) {}
625          }
626      }
627  
628      /**
629       * For use as ThreadFactory in constructors
630       */
631 <    static class SimpleThreadFactory implements ThreadFactory {
631 >    public static class SimpleThreadFactory implements ThreadFactory {
632          public Thread newThread(Runnable r) {
633              return new Thread(r);
634          }
635      }
636  
637 <    static class TrackedShortRunnable implements Runnable {
638 <        volatile boolean done = false;
637 >    public static class TrackedShortRunnable implements Runnable {
638 >        public volatile boolean done = false;
639          public void run() {
640              try {
641                  Thread.sleep(SMALL_DELAY_MS);
642                  done = true;
643 <            } catch (InterruptedException ok) {
643 <            }
643 >            } catch (InterruptedException ok) {}
644          }
645      }
646  
647 <    static class TrackedMediumRunnable implements Runnable {
648 <        volatile boolean done = false;
647 >    public static class TrackedMediumRunnable implements Runnable {
648 >        public volatile boolean done = false;
649          public void run() {
650              try {
651                  Thread.sleep(MEDIUM_DELAY_MS);
652                  done = true;
653 <            } catch (InterruptedException ok) {
654 <            }
653 >            } catch (InterruptedException ok) {}
654          }
655      }
656  
657 <    static class TrackedLongRunnable implements Runnable {
658 <        volatile boolean done = false;
657 >    public static class TrackedLongRunnable implements Runnable {
658 >        public volatile boolean done = false;
659          public void run() {
660              try {
661                  Thread.sleep(LONG_DELAY_MS);
662                  done = true;
663 <            } catch (InterruptedException ok) {
665 <            }
663 >            } catch (InterruptedException ok) {}
664          }
665      }
666  
667 <    static class TrackedNoOpRunnable implements Runnable {
668 <        volatile boolean done = false;
667 >    public static class TrackedNoOpRunnable implements Runnable {
668 >        public volatile boolean done = false;
669          public void run() {
670              done = true;
671          }
672      }
673  
674 <    static class TrackedCallable implements Callable {
675 <        volatile boolean done = false;
674 >    public static class TrackedCallable implements Callable {
675 >        public volatile boolean done = false;
676          public Object call() {
677              try {
678                  Thread.sleep(SMALL_DELAY_MS);
679                  done = true;
680 <            } catch (InterruptedException ok) {
683 <            }
680 >            } catch (InterruptedException ok) {}
681              return Boolean.TRUE;
682          }
683      }
# Line 689 | Line 686 | public class JSR166TestCase extends Test
686      /**
687       * For use as RejectedExecutionHandler in constructors
688       */
689 <    static class NoOpREHandler implements RejectedExecutionHandler {
689 >    public static class NoOpREHandler implements RejectedExecutionHandler {
690          public void rejectedExecution(Runnable r,
691                                        ThreadPoolExecutor executor) {}
692      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines