ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.124 by jsr166, Mon Jul 17 22:27:31 2017 UTC vs.
Revision 1.127 by dl, Tue Jan 26 13:33:06 2021 UTC

# Line 563 | Line 563 | public class ThreadPoolExecutorTest exte
563                                     q);
564          try (PoolCleaner cleaner = cleaner(p, done)) {
565              final CountDownLatch threadStarted = new CountDownLatch(1);
566 <            FutureTask[] tasks = new FutureTask[5];
566 >            FutureTask[] rtasks = new FutureTask[5];
567 >            @SuppressWarnings("unchecked")
568 >            FutureTask<Boolean>[] tasks = (FutureTask<Boolean>[])rtasks;
569              for (int i = 0; i < tasks.length; i++) {
570 <                Callable task = new CheckedCallable<Boolean>() {
570 >                Callable<Boolean> task = new CheckedCallable<Boolean>() {
571                      public Boolean realCall() throws InterruptedException {
572                          threadStarted.countDown();
573                          assertSame(q, p.getQueue());
574                          await(done);
575                          return Boolean.TRUE;
576                      }};
577 <                tasks[i] = new FutureTask(task);
577 >                tasks[i] = new FutureTask<Boolean>(task);
578                  p.execute(tasks[i]);
579              }
580              await(threadStarted);
# Line 629 | Line 631 | public class ThreadPoolExecutorTest exte
631                                     LONG_DELAY_MS, MILLISECONDS,
632                                     q);
633          try (PoolCleaner cleaner = cleaner(p, done)) {
634 <            FutureTask[] tasks = new FutureTask[5];
634 >            FutureTask[] rtasks = new FutureTask[5];
635 >            @SuppressWarnings("unchecked")
636 >            FutureTask<Boolean>[] tasks = (FutureTask<Boolean>[])rtasks;
637              for (int i = 0; i < tasks.length; i++) {
638 <                Callable task = new CheckedCallable<Boolean>() {
638 >                Callable<Boolean> task = new CheckedCallable<Boolean>() {
639                      public Boolean realCall() throws InterruptedException {
640                          threadStarted.countDown();
641                          await(done);
642                          return Boolean.TRUE;
643                      }};
644 <                tasks[i] = new FutureTask(task);
644 >                tasks[i] = new FutureTask<Boolean>(task);
645                  p.execute(tasks[i]);
646              }
647              await(threadStarted);
# Line 672 | Line 676 | public class ThreadPoolExecutorTest exte
676          Runnable waiter = new CheckedRunnable() { public void realRun() {
677              threadsStarted.countDown();
678              try {
679 <                MILLISECONDS.sleep(2 * LONG_DELAY_MS);
679 >                MILLISECONDS.sleep(LONGER_DELAY_MS);
680              } catch (InterruptedException success) {}
681              ran.getAndIncrement();
682          }};
# Line 759 | Line 763 | public class ThreadPoolExecutorTest exte
763      public void testConstructorNullPointerException() {
764          try {
765              new ThreadPoolExecutor(1, 2, 1L, SECONDS,
766 <                                   (BlockingQueue) null);
766 >                                   (BlockingQueue<Runnable>) null);
767              shouldThrow();
768          } catch (NullPointerException success) {}
769      }
# Line 830 | Line 834 | public class ThreadPoolExecutorTest exte
834      public void testConstructorNullPointerException2() {
835          try {
836              new ThreadPoolExecutor(1, 2, 1L, SECONDS,
837 <                                   (BlockingQueue) null,
837 >                                   (BlockingQueue<Runnable>) null,
838                                     new SimpleThreadFactory());
839              shouldThrow();
840          } catch (NullPointerException success) {}
# Line 914 | Line 918 | public class ThreadPoolExecutorTest exte
918      public void testConstructorNullPointerException4() {
919          try {
920              new ThreadPoolExecutor(1, 2, 1L, SECONDS,
921 <                                   (BlockingQueue) null,
921 >                                   (BlockingQueue<Runnable>) null,
922                                     new NoOpREHandler());
923              shouldThrow();
924          } catch (NullPointerException success) {}
# Line 1003 | Line 1007 | public class ThreadPoolExecutorTest exte
1007      public void testConstructorNullPointerException6() {
1008          try {
1009              new ThreadPoolExecutor(1, 2, 1L, SECONDS,
1010 <                                   (BlockingQueue) null,
1010 >                                   (BlockingQueue<Runnable>) null,
1011                                     new SimpleThreadFactory(),
1012                                     new NoOpREHandler());
1013              shouldThrow();
# Line 1050 | Line 1054 | public class ThreadPoolExecutorTest exte
1054              final CountDownLatch threadStarted = new CountDownLatch(1);
1055              Thread t = newStartedThread(new CheckedInterruptedRunnable() {
1056                  public void realRun() throws Exception {
1057 <                    Callable task = new CheckedCallable<Boolean>() {
1057 >                    Callable<Boolean> task = new CheckedCallable<Boolean>() {
1058                          public Boolean realCall() throws InterruptedException {
1059                              threadStarted.countDown();
1060                              await(done);
# Line 1789 | Line 1793 | public class ThreadPoolExecutorTest exte
1793                      p.invokeAll(tasks, timeout, MILLISECONDS);
1794                  assertEquals(tasks.size(), futures.size());
1795                  assertTrue(millisElapsedSince(startTime) >= timeout);
1796 <                for (Future future : futures)
1796 >                for (Future<?> future : futures)
1797                      assertTrue(future.isDone());
1798                  assertTrue(futures.get(1).isCancelled());
1799                  try {
# Line 1904 | Line 1908 | public class ThreadPoolExecutorTest exte
1908          final ThreadPoolExecutor p =
1909              new ThreadPoolExecutor(1, 30,
1910                                     60, SECONDS,
1911 <                                   new ArrayBlockingQueue(30));
1911 >                                   new ArrayBlockingQueue<Runnable>(30));
1912          try (PoolCleaner cleaner = cleaner(p)) {
1913              for (int i = 0; i < nTasks; ++i) {
1914                  for (;;) {
# Line 1984 | Line 1988 | public class ThreadPoolExecutorTest exte
1988          assertTrue(p.getQueue().isEmpty());
1989      }
1990  
1991 +    public void testThreadFactoryReturnsTerminatedThread_shouldThrow() {
1992 +        if (!testImplementationDetails)
1993 +            return;
1994 +
1995 +        ThreadFactory returnsTerminatedThread = runnableIgnored -> {
1996 +            Thread thread = new Thread(() -> {});
1997 +            thread.start();
1998 +            try { thread.join(); }
1999 +            catch (InterruptedException ex) { throw new Error(ex); }
2000 +            return thread;
2001 +        };
2002 +        ThreadPoolExecutor p =
2003 +            new ThreadPoolExecutor(1, 1, 1, SECONDS,
2004 +                                   new ArrayBlockingQueue<Runnable>(1),
2005 +                                   returnsTerminatedThread);
2006 +        try (PoolCleaner cleaner = cleaner(p)) {
2007 +            assertThrows(IllegalThreadStateException.class,
2008 +                         () -> p.execute(() -> {}));
2009 +        }
2010 +    }
2011 +
2012 +    public void testThreadFactoryReturnsStartedThread_shouldThrow() {
2013 +        if (!testImplementationDetails)
2014 +            return;
2015 +
2016 +        CountDownLatch latch = new CountDownLatch(1);
2017 +        Runnable awaitLatch = () -> {
2018 +            try { latch.await(); }
2019 +            catch (InterruptedException ex) { throw new Error(ex); }};
2020 +        ThreadFactory returnsStartedThread = runnable -> {
2021 +            Thread thread = new Thread(awaitLatch);
2022 +            thread.start();
2023 +            return thread;
2024 +        };
2025 +        ThreadPoolExecutor p =
2026 +            new ThreadPoolExecutor(1, 1, 1, SECONDS,
2027 +                                   new ArrayBlockingQueue<Runnable>(1),
2028 +                                   returnsStartedThread);
2029 +        try (PoolCleaner cleaner = cleaner(p)) {
2030 +            assertThrows(IllegalThreadStateException.class,
2031 +                         () -> p.execute(() -> {}));
2032 +            latch.countDown();
2033 +        }
2034 +    }
2035 +
2036   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines