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

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.28 by jsr166, Sat May 7 19:49:37 2011 UTC vs.
Revision 1.29 by jsr166, Fri May 27 19:35:24 2011 UTC

# Line 115 | Line 115 | public class ThreadPoolExecutorSubclassT
115          }
116      }
117  
118
118      static class CustomTPE extends ThreadPoolExecutor {
119          protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
120              return new CustomTask<V>(c);
# Line 188 | Line 187 | public class ThreadPoolExecutorSubclassT
187          }
188      }
189  
191
190      /**
191       * execute successfully executes a runnable
192       */
# Line 315 | Line 313 | public class ThreadPoolExecutorSubclassT
313          joinPool(p);
314      }
315  
318
316      /**
317       * getThreadFactory returns factory in constructor if not set
318       */
# Line 337 | Line 334 | public class ThreadPoolExecutorSubclassT
334          joinPool(p);
335      }
336  
340
337      /**
338       * setThreadFactory(null) throws NPE
339       */
# Line 374 | Line 370 | public class ThreadPoolExecutorSubclassT
370          joinPool(p);
371      }
372  
377
373      /**
374       * setRejectedExecutionHandler(null) throws NPE
375       */
# Line 389 | Line 384 | public class ThreadPoolExecutorSubclassT
384          }
385      }
386  
392
387      /**
388       * getLargestPoolSize increases, but doesn't overestimate, when
389       * multiple threads active
# Line 495 | Line 489 | public class ThreadPoolExecutorSubclassT
489          joinPool(p);
490      }
491  
498
492      /**
493       * isTerminated is false before termination, true after
494       */
# Line 689 | Line 682 | public class ThreadPoolExecutorSubclassT
682  
683      // Exception Tests
684  
692
685      /**
686       * Constructor throws if corePoolSize argument is less than zero
687       */
# Line 750 | Line 742 | public class ThreadPoolExecutorSubclassT
742          } catch (NullPointerException success) {}
743      }
744  
753
754
745      /**
746       * Constructor throws if corePoolSize argument is less than zero
747       */
# Line 823 | Line 813 | public class ThreadPoolExecutorSubclassT
813          } catch (NullPointerException success) {}
814      }
815  
826
816      /**
817       * Constructor throws if corePoolSize argument is less than zero
818       */
# Line 895 | Line 884 | public class ThreadPoolExecutorSubclassT
884          } catch (NullPointerException success) {}
885      }
886  
898
887      /**
888       * Constructor throws if corePoolSize argument is less than zero
889       */
# Line 981 | Line 969 | public class ThreadPoolExecutorSubclassT
969          } catch (NullPointerException success) {}
970      }
971  
984
972      /**
973       * execute throws RejectedExecutionException if saturated.
974       */
# Line 1131 | Line 1118 | public class ThreadPoolExecutorSubclassT
1118          }
1119      }
1120  
1134
1121      /**
1122       * execute using DiscardOldestPolicy drops task on shutdown
1123       */
# Line 1149 | Line 1135 | public class ThreadPoolExecutorSubclassT
1135          }
1136      }
1137  
1152
1138      /**
1139       * execute(null) throws NPE
1140       */
# Line 1214 | Line 1199 | public class ThreadPoolExecutorSubclassT
1199          joinPool(p);
1200      }
1201  
1217
1202      /**
1203       * setKeepAliveTime throws IllegalArgumentException
1204       * when given a negative value
# Line 1303 | Line 1287 | public class ThreadPoolExecutorSubclassT
1287          }
1288      }
1289  
1306
1290      /**
1291       * invokeAny(null) throws NPE
1292       */
# Line 1465 | Line 1448 | public class ThreadPoolExecutorSubclassT
1448          }
1449      }
1450  
1468
1469
1451      /**
1452       * timed invokeAny(null) throws NPE
1453       */
# Line 1726 | Line 1707 | public class ThreadPoolExecutorSubclassT
1707       * allowCoreThreadTimeOut(true) causes idle threads to time out
1708       */
1709      public void testAllowCoreThreadTimeOut_true() throws Exception {
1710 +        long coreThreadTimeOut = SHORT_DELAY_MS;
1711          final ThreadPoolExecutor p =
1712              new CustomTPE(2, 10,
1713 <                          SHORT_DELAY_MS, MILLISECONDS,
1713 >                          coreThreadTimeOut, MILLISECONDS,
1714                            new ArrayBlockingQueue<Runnable>(10));
1715          final CountDownLatch threadStarted = new CountDownLatch(1);
1716          try {
# Line 1738 | Line 1720 | public class ThreadPoolExecutorSubclassT
1720                      threadStarted.countDown();
1721                      assertEquals(1, p.getPoolSize());
1722                  }});
1723 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
1724 <            for (int i = 0; i < (MEDIUM_DELAY_MS/10); i++) {
1725 <                if (p.getPoolSize() == 0)
1726 <                    break;
1727 <                delay(10);
1728 <            }
1723 >            await(threadStarted);
1724 >            delay(coreThreadTimeOut);
1725 >            long startTime = System.nanoTime();
1726 >            while (p.getPoolSize() > 0
1727 >                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
1728 >                Thread.yield();
1729 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1730              assertEquals(0, p.getPoolSize());
1731          } finally {
1732              joinPool(p);
# Line 1754 | Line 1737 | public class ThreadPoolExecutorSubclassT
1737       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1738       */
1739      public void testAllowCoreThreadTimeOut_false() throws Exception {
1740 +        long coreThreadTimeOut = SHORT_DELAY_MS;
1741          final ThreadPoolExecutor p =
1742              new CustomTPE(2, 10,
1743 <                          SHORT_DELAY_MS, MILLISECONDS,
1743 >                          coreThreadTimeOut, MILLISECONDS,
1744                            new ArrayBlockingQueue<Runnable>(10));
1745          final CountDownLatch threadStarted = new CountDownLatch(1);
1746          try {
# Line 1766 | Line 1750 | public class ThreadPoolExecutorSubclassT
1750                      threadStarted.countDown();
1751                      assertTrue(p.getPoolSize() >= 1);
1752                  }});
1753 <            delay(SMALL_DELAY_MS);
1753 >            delay(2 * coreThreadTimeOut);
1754              assertTrue(p.getPoolSize() >= 1);
1755          } finally {
1756              joinPool(p);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines