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.43 by jsr166, Sat May 7 19:49:37 2011 UTC vs.
Revision 1.44 by jsr166, Fri May 27 19:35:24 2011 UTC

# Line 46 | Line 46 | public class ThreadPoolExecutorTest exte
46          }
47      }
48  
49
49      /**
50       * execute successfully executes a runnable
51       */
# Line 185 | Line 184 | public class ThreadPoolExecutorTest exte
184          joinPool(p);
185      }
186  
188
187      /**
188       * getThreadFactory returns factory in constructor if not set
189       */
# Line 215 | Line 213 | public class ThreadPoolExecutorTest exte
213          joinPool(p);
214      }
215  
218
216      /**
217       * setThreadFactory(null) throws NPE
218       */
# Line 262 | Line 259 | public class ThreadPoolExecutorTest exte
259          joinPool(p);
260      }
261  
265
262      /**
263       * setRejectedExecutionHandler(null) throws NPE
264       */
# Line 280 | Line 276 | public class ThreadPoolExecutorTest exte
276          }
277      }
278  
283
279      /**
280       * getLargestPoolSize increases, but doesn't overestimate, when
281       * multiple threads active
# Line 391 | Line 386 | public class ThreadPoolExecutorTest exte
386          joinPool(p);
387      }
388  
394
389      /**
390       * isTerminated is false before termination, true after
391       */
# Line 587 | Line 581 | public class ThreadPoolExecutorTest exte
581  
582      // Exception Tests
583  
590
584      /**
585       * Constructor throws if corePoolSize argument is less than zero
586       */
# Line 660 | Line 653 | public class ThreadPoolExecutorTest exte
653          } catch (NullPointerException success) {}
654      }
655  
663
664
656      /**
657       * Constructor throws if corePoolSize argument is less than zero
658       */
# Line 753 | Line 744 | public class ThreadPoolExecutorTest exte
744          } catch (NullPointerException success) {}
745      }
746  
756
747      /**
748       * Constructor throws if corePoolSize argument is less than zero
749       */
# Line 845 | Line 835 | public class ThreadPoolExecutorTest exte
835          } catch (NullPointerException success) {}
836      }
837  
848
838      /**
839       * Constructor throws if corePoolSize argument is less than zero
840       */
# Line 1212 | Line 1201 | public class ThreadPoolExecutorTest exte
1201          }
1202      }
1203  
1215
1204      /**
1205       * execute using DiscardOldestPolicy drops task on shutdown
1206       */
# Line 1234 | Line 1222 | public class ThreadPoolExecutorTest exte
1222          }
1223      }
1224  
1237
1225      /**
1226       * execute(null) throws NPE
1227       */
# Line 1307 | Line 1294 | public class ThreadPoolExecutorTest exte
1294          joinPool(p);
1295      }
1296  
1310
1297      /**
1298       * setKeepAliveTime throws IllegalArgumentException
1299       * when given a negative value
# Line 1406 | Line 1392 | public class ThreadPoolExecutorTest exte
1392          }
1393      }
1394  
1409
1395      /**
1396       * invokeAny(null) throws NPE
1397       */
# Line 1600 | Line 1585 | public class ThreadPoolExecutorTest exte
1585          }
1586      }
1587  
1603
1604
1588      /**
1589       * timed invokeAny(null) throws NPE
1590       */
# Line 1903 | Line 1886 | public class ThreadPoolExecutorTest exte
1886       * allowCoreThreadTimeOut(true) causes idle threads to time out
1887       */
1888      public void testAllowCoreThreadTimeOut_true() throws Exception {
1889 +        long coreThreadTimeOut = SHORT_DELAY_MS;
1890          final ThreadPoolExecutor p =
1891              new ThreadPoolExecutor(2, 10,
1892 <                                   SHORT_DELAY_MS, MILLISECONDS,
1892 >                                   coreThreadTimeOut, MILLISECONDS,
1893                                     new ArrayBlockingQueue<Runnable>(10));
1894          final CountDownLatch threadStarted = new CountDownLatch(1);
1895          try {
1896              p.allowCoreThreadTimeOut(true);
1897              p.execute(new CheckedRunnable() {
1898 <                public void realRun() throws InterruptedException {
1898 >                public void realRun() {
1899                      threadStarted.countDown();
1900                      assertEquals(1, p.getPoolSize());
1901                  }});
1902 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
1903 <            for (int i = 0; i < (MEDIUM_DELAY_MS/10); i++) {
1904 <                if (p.getPoolSize() == 0)
1905 <                    break;
1906 <                delay(10);
1907 <            }
1902 >            await(threadStarted);
1903 >            delay(coreThreadTimeOut);
1904 >            long startTime = System.nanoTime();
1905 >            while (p.getPoolSize() > 0
1906 >                   && millisElapsedSince(startTime) < LONG_DELAY_MS)
1907 >                Thread.yield();
1908 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1909              assertEquals(0, p.getPoolSize());
1910          } finally {
1911              joinPool(p);
# Line 1931 | Line 1916 | public class ThreadPoolExecutorTest exte
1916       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1917       */
1918      public void testAllowCoreThreadTimeOut_false() throws Exception {
1919 +        long coreThreadTimeOut = SHORT_DELAY_MS;
1920          final ThreadPoolExecutor p =
1921              new ThreadPoolExecutor(2, 10,
1922 <                                   SHORT_DELAY_MS, MILLISECONDS,
1922 >                                   coreThreadTimeOut, MILLISECONDS,
1923                                     new ArrayBlockingQueue<Runnable>(10));
1924          final CountDownLatch threadStarted = new CountDownLatch(1);
1925          try {
# Line 1943 | Line 1929 | public class ThreadPoolExecutorTest exte
1929                      threadStarted.countDown();
1930                      assertTrue(p.getPoolSize() >= 1);
1931                  }});
1932 <            delay(SMALL_DELAY_MS);
1932 >            delay(2 * coreThreadTimeOut);
1933              assertTrue(p.getPoolSize() >= 1);
1934          } finally {
1935              joinPool(p);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines