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.27 by jsr166, Thu May 12 03:20:56 2005 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 137 | Line 145 | public class JSR166TestCase extends Test
145          suite.addTest(new TestSuite(CountDownLatchTest.class));
146          suite.addTest(new TestSuite(CyclicBarrierTest.class));
147          suite.addTest(new TestSuite(DelayQueueTest.class));
148 +        suite.addTest(new TestSuite(EntryTest.class));
149          suite.addTest(new TestSuite(ExchangerTest.class));
150          suite.addTest(new TestSuite(ExecutorsTest.class));
151          suite.addTest(new TestSuite(ExecutorCompletionServiceTest.class));
# Line 150 | Line 159 | public class JSR166TestCase extends Test
159          suite.addTest(new TestSuite(ReentrantLockTest.class));
160          suite.addTest(new TestSuite(ReentrantReadWriteLockTest.class));
161          suite.addTest(new TestSuite(ScheduledExecutorTest.class));
162 +        suite.addTest(new TestSuite(ScheduledExecutorSubclassTest.class));
163          suite.addTest(new TestSuite(SemaphoreTest.class));
164          suite.addTest(new TestSuite(SynchronousQueueTest.class));
165          suite.addTest(new TestSuite(SystemTest.class));
166          suite.addTest(new TestSuite(ThreadLocalTest.class));
167          suite.addTest(new TestSuite(ThreadPoolExecutorTest.class));
168 +        suite.addTest(new TestSuite(ThreadPoolExecutorSubclassTest.class));
169          suite.addTest(new TestSuite(ThreadTest.class));
170          suite.addTest(new TestSuite(TimeUnitTest.class));
171          suite.addTest(new TestSuite(TreeMapTest.class));
# Line 278 | 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 290 | 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 297 | 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 320 | 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 343 | Line 375 | public class JSR166TestCase extends Test
375      static final Integer m3  = new Integer(-3);
376      static final Integer m4 = new Integer(-4);
377      static final Integer m5 = new Integer(-5);
378 +    static final Integer m6 = new Integer(-6);
379      static final Integer m10 = new Integer(-10);
380  
381  
# Line 370 | 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 392 | 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 {
398 <                Thread.sleep(SHORT_DELAY_MS);
399 <            }
400 <            catch(Exception e) {
401 <                threadUnexpectedException();
402 <            }
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 {
409 <                Thread.sleep(SHORT_DELAY_MS);
410 <                threadShouldThrow();
411 <            }
412 <            catch(InterruptedException success) {
413 <            }
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 {
420 <                Thread.sleep(SMALL_DELAY_MS);
421 <            }
422 <            catch(Exception e) {
423 <                threadUnexpectedException();
424 <            }
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 {
441 <                Thread.sleep(SMALL_DELAY_MS);
442 <            }
443 <            catch(Exception e) {
444 <                threadUnexpectedException();
445 <            }
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 {
453 <                Thread.sleep(SMALL_DELAY_MS);
454 <                threadShouldThrow();
455 <            }
456 <            catch(InterruptedException success) {
457 <            }
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() {
464 <            try {
465 <                Thread.sleep(MEDIUM_DELAY_MS);
466 <            }
467 <            catch(Exception e) {
468 <                threadUnexpectedException();
469 <            }
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 {
476 <                Thread.sleep(MEDIUM_DELAY_MS);
477 <                threadShouldThrow();
478 <            }
479 <            catch(InterruptedException success) {
480 <            }
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 504 | 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 516 | 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 527 | 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 538 | 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 556 | 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 566 | 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  
573
610   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines