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.28 by dl, Fri May 20 16:30:17 2005 UTC vs.
Revision 1.37 by dl, Tue Aug 4 00:23:18 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 292 | Line 301 | public class JSR166TestCase extends Test
301          fail("Unexpected exception");
302      }
303  
304 +    /**
305 +     * threadFail with message "Unexpected exception", with argument
306 +     */
307 +    public void threadUnexpectedException(Throwable ex) {
308 +        threadFailed = true;
309 +        ex.printStackTrace();
310 +        fail("Unexpected exception: " + ex);
311 +    }
312  
313      /**
314       * Wait out termination of a thread pool or fail doing so
# Line 299 | Line 316 | public class JSR166TestCase extends Test
316      public void joinPool(ExecutorService exec) {
317          try {
318              exec.shutdown();
319 <            assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
320 <        } catch(SecurityException ok) {
319 >            assertTrue(exec.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
320 >        } catch (SecurityException ok) {
321              // Allowed in case test doesn't have privs
322 <        } catch(InterruptedException ie) {
322 >        } catch (InterruptedException ie) {
323              fail("Unexpected exception");
324          }
325      }
# Line 322 | Line 339 | public class JSR166TestCase extends Test
339          fail("Unexpected exception");
340      }
341  
342 +    /**
343 +     * fail with message "Unexpected exception", with argument
344 +     */
345 +    public void unexpectedException(Throwable ex) {
346 +        ex.printStackTrace();
347 +        fail("Unexpected exception: " + ex);
348 +    }
349 +
350  
351      /**
352       * The number of elements to place in collections, arrays, etc.
# Line 345 | Line 370 | public class JSR166TestCase extends Test
370      static final Integer m3  = new Integer(-3);
371      static final Integer m4 = new Integer(-4);
372      static final Integer m5 = new Integer(-5);
373 +    static final Integer m6 = new Integer(-6);
374      static final Integer m10 = new Integer(-10);
375  
376  
# Line 372 | Line 398 | public class JSR166TestCase extends Test
398  
399      // Some convenient Runnable classes
400  
401 +    abstract class CheckedRunnable implements Runnable {
402 +        abstract void realRun() throws Throwable;
403 +
404 +        public final void run() {
405 +            try {
406 +                realRun();
407 +            } catch (Throwable t) {
408 +                threadUnexpectedException(t);
409 +            }
410 +        }
411 +    }
412 +
413 +    abstract class CheckedInterruptedRunnable implements Runnable {
414 +        abstract void realRun() throws Throwable;
415 +
416 +        public final void run() {
417 +            try {
418 +                realRun();
419 +                threadShouldThrow();
420 +            } catch (InterruptedException success) {
421 +            } catch (Throwable t) {
422 +                threadUnexpectedException(t);
423 +            }
424 +        }
425 +    }
426 +
427 +    abstract class CheckedCallable<T> implements Callable<T> {
428 +        abstract T realCall() throws Throwable;
429 +
430 +        public final T call() {
431 +            try {
432 +                return realCall();
433 +            } catch (Throwable t) {
434 +                threadUnexpectedException(t);
435 +                return null;
436 +            }
437 +        }
438 +    }
439 +
440      static class NoOpRunnable implements Runnable {
441          public void run() {}
442      }
# Line 394 | Line 459 | public class JSR166TestCase extends Test
459          public Integer call() { return one; }
460      }
461  
462 <    class ShortRunnable implements Runnable {
463 <        public void run() {
464 <            try {
400 <                Thread.sleep(SHORT_DELAY_MS);
401 <            }
402 <            catch(Exception e) {
403 <                threadUnexpectedException();
404 <            }
462 >    class ShortRunnable extends CheckedRunnable {
463 >        void realRun() throws Throwable {
464 >            Thread.sleep(SHORT_DELAY_MS);
465          }
466      }
467  
468 <    class ShortInterruptedRunnable implements Runnable {
469 <        public void run() {
470 <            try {
411 <                Thread.sleep(SHORT_DELAY_MS);
412 <                threadShouldThrow();
413 <            }
414 <            catch(InterruptedException success) {
415 <            }
468 >    class ShortInterruptedRunnable extends CheckedInterruptedRunnable {
469 >        void realRun() throws InterruptedException {
470 >            Thread.sleep(SHORT_DELAY_MS);
471          }
472      }
473  
474 <    class SmallRunnable implements Runnable {
475 <        public void run() {
476 <            try {
422 <                Thread.sleep(SMALL_DELAY_MS);
423 <            }
424 <            catch(Exception e) {
425 <                threadUnexpectedException();
426 <            }
474 >    class SmallRunnable extends CheckedRunnable {
475 >        void realRun() throws Throwable {
476 >            Thread.sleep(SMALL_DELAY_MS);
477          }
478      }
479  
480 <    class SmallPossiblyInterruptedRunnable implements Runnable {
481 <        public void run() {
480 >    class SmallPossiblyInterruptedRunnable extends CheckedRunnable {
481 >        void realRun() {
482              try {
483                  Thread.sleep(SMALL_DELAY_MS);
484              }
485 <            catch(Exception e) {
485 >            catch (InterruptedException ok) {
486              }
487          }
488      }
489  
490 <    class SmallCallable implements Callable {
491 <        public Object call() {
492 <            try {
443 <                Thread.sleep(SMALL_DELAY_MS);
444 <            }
445 <            catch(Exception e) {
446 <                threadUnexpectedException();
447 <            }
490 >    class SmallCallable extends CheckedCallable {
491 >        Object realCall() throws Throwable {
492 >            Thread.sleep(SMALL_DELAY_MS);
493              return Boolean.TRUE;
494          }
495      }
496  
497 <    class SmallInterruptedRunnable implements Runnable {
498 <        public void run() {
499 <            try {
455 <                Thread.sleep(SMALL_DELAY_MS);
456 <                threadShouldThrow();
457 <            }
458 <            catch(InterruptedException success) {
459 <            }
497 >    class SmallInterruptedRunnable extends CheckedInterruptedRunnable {
498 >        void realRun() throws InterruptedException {
499 >            Thread.sleep(SMALL_DELAY_MS);
500          }
501      }
502  
503 <
504 <    class MediumRunnable implements Runnable {
505 <        public void run() {
466 <            try {
467 <                Thread.sleep(MEDIUM_DELAY_MS);
468 <            }
469 <            catch(Exception e) {
470 <                threadUnexpectedException();
471 <            }
503 >    class MediumRunnable extends CheckedRunnable {
504 >        void realRun() throws Throwable {
505 >            Thread.sleep(MEDIUM_DELAY_MS);
506          }
507      }
508  
509 <    class MediumInterruptedRunnable implements Runnable {
510 <        public void run() {
511 <            try {
478 <                Thread.sleep(MEDIUM_DELAY_MS);
479 <                threadShouldThrow();
480 <            }
481 <            catch(InterruptedException success) {
482 <            }
509 >    class MediumInterruptedRunnable extends CheckedInterruptedRunnable {
510 >        void realRun() throws InterruptedException {
511 >            Thread.sleep(MEDIUM_DELAY_MS);
512          }
513      }
514  
515 <    class MediumPossiblyInterruptedRunnable implements Runnable {
516 <        public void run() {
515 >    class MediumPossiblyInterruptedRunnable extends CheckedRunnable {
516 >        void realRun() {
517              try {
518                  Thread.sleep(MEDIUM_DELAY_MS);
519              }
520 <            catch(InterruptedException success) {
520 >            catch (InterruptedException ok) {
521              }
522          }
523      }
524  
525 <    class LongPossiblyInterruptedRunnable implements Runnable {
526 <        public void run() {
525 >    class LongPossiblyInterruptedRunnable extends CheckedRunnable {
526 >        void realRun() {
527              try {
528                  Thread.sleep(LONG_DELAY_MS);
529              }
530 <            catch(InterruptedException success) {
530 >            catch (InterruptedException ok) {
531              }
532          }
533      }
# Line 506 | Line 535 | public class JSR166TestCase extends Test
535      /**
536       * For use as ThreadFactory in constructors
537       */
538 <    static class SimpleThreadFactory implements ThreadFactory{
539 <        public Thread newThread(Runnable r){
538 >    static class SimpleThreadFactory implements ThreadFactory {
539 >        public Thread newThread(Runnable r) {
540              return new Thread(r);
541          }
542      }
# Line 518 | Line 547 | public class JSR166TestCase extends Test
547              try {
548                  Thread.sleep(SMALL_DELAY_MS);
549                  done = true;
550 <            } catch(Exception e){
550 >            } catch (Exception e) {
551              }
552          }
553      }
# Line 529 | Line 558 | public class JSR166TestCase extends Test
558              try {
559                  Thread.sleep(MEDIUM_DELAY_MS);
560                  done = true;
561 <            } catch(Exception e){
561 >            } catch (Exception e) {
562              }
563          }
564      }
# Line 540 | Line 569 | public class JSR166TestCase extends Test
569              try {
570                  Thread.sleep(LONG_DELAY_MS);
571                  done = true;
572 <            } catch(Exception e){
572 >            } catch (Exception e) {
573              }
574          }
575      }
# Line 558 | Line 587 | public class JSR166TestCase extends Test
587              try {
588                  Thread.sleep(SMALL_DELAY_MS);
589                  done = true;
590 <            } catch(Exception e){
590 >            } catch (Exception e) {
591              }
592              return Boolean.TRUE;
593          }
# Line 568 | Line 597 | public class JSR166TestCase extends Test
597      /**
598       * For use as RejectedExecutionHandler in constructors
599       */
600 <    static class NoOpREHandler implements RejectedExecutionHandler{
601 <        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
600 >    static class NoOpREHandler implements RejectedExecutionHandler {
601 >        public void rejectedExecution(Runnable r,
602 >                                      ThreadPoolExecutor executor) {}
603      }
604  
575
605   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines