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.69 by jsr166, Sun Oct 4 01:29:09 2015 UTC vs.
Revision 1.79 by jsr166, Sun Oct 4 02:15:08 2015 UTC

# Line 119 | Line 119 | public class ThreadPoolExecutorTest exte
119                      assertEquals(1, p.getActiveCount());
120                      done.await();
121                  }});
122 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
122 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
123              assertEquals(1, p.getActiveCount());
124          } finally {
125              done.countDown();
# Line 230 | Line 230 | public class ThreadPoolExecutorTest exte
230              new ThreadPoolExecutor(2, 2,
231                                     1000, MILLISECONDS,
232                                     new ArrayBlockingQueue<Runnable>(10));
233 <        assertEquals(1, p.getKeepAliveTime(SECONDS));
234 <        joinPool(p);
233 >        try (PoolCleaner cleaner = cleaner(p)) {
234 >            assertEquals(1, p.getKeepAliveTime(SECONDS));
235 >        }
236      }
237  
238      /**
239       * getThreadFactory returns factory in constructor if not set
240       */
241      public void testGetThreadFactory() {
242 <        ThreadFactory tf = new SimpleThreadFactory();
242 >        ThreadFactory threadFactory = new SimpleThreadFactory();
243          final ThreadPoolExecutor p =
244              new ThreadPoolExecutor(1, 2,
245                                     LONG_DELAY_MS, MILLISECONDS,
246                                     new ArrayBlockingQueue<Runnable>(10),
247 <                                   tf,
247 >                                   threadFactory,
248                                     new NoOpREHandler());
249 <        assertSame(tf, p.getThreadFactory());
250 <        joinPool(p);
249 >        try (PoolCleaner cleaner = cleaner(p)) {
250 >            assertSame(threadFactory, p.getThreadFactory());
251 >        }
252      }
253  
254      /**
# Line 257 | Line 259 | public class ThreadPoolExecutorTest exte
259              new ThreadPoolExecutor(1, 2,
260                                     LONG_DELAY_MS, MILLISECONDS,
261                                     new ArrayBlockingQueue<Runnable>(10));
262 <        ThreadFactory tf = new SimpleThreadFactory();
263 <        p.setThreadFactory(tf);
264 <        assertSame(tf, p.getThreadFactory());
265 <        joinPool(p);
262 >        try (PoolCleaner cleaner = cleaner(p)) {
263 >            ThreadFactory threadFactory = new SimpleThreadFactory();
264 >            p.setThreadFactory(threadFactory);
265 >            assertSame(threadFactory, p.getThreadFactory());
266 >        }
267      }
268  
269      /**
# Line 271 | Line 274 | public class ThreadPoolExecutorTest exte
274              new ThreadPoolExecutor(1, 2,
275                                     LONG_DELAY_MS, MILLISECONDS,
276                                     new ArrayBlockingQueue<Runnable>(10));
277 <        try {
278 <            p.setThreadFactory(null);
279 <            shouldThrow();
280 <        } catch (NullPointerException success) {
281 <        } finally {
279 <            joinPool(p);
277 >        try (PoolCleaner cleaner = cleaner(p)) {
278 >            try {
279 >                p.setThreadFactory(null);
280 >                shouldThrow();
281 >            } catch (NullPointerException success) {}
282          }
283      }
284  
# Line 284 | Line 286 | public class ThreadPoolExecutorTest exte
286       * getRejectedExecutionHandler returns handler in constructor if not set
287       */
288      public void testGetRejectedExecutionHandler() {
289 <        final RejectedExecutionHandler h = new NoOpREHandler();
289 >        final RejectedExecutionHandler handler = new NoOpREHandler();
290          final ThreadPoolExecutor p =
291              new ThreadPoolExecutor(1, 2,
292                                     LONG_DELAY_MS, MILLISECONDS,
293                                     new ArrayBlockingQueue<Runnable>(10),
294 <                                   h);
295 <        assertSame(h, p.getRejectedExecutionHandler());
296 <        joinPool(p);
294 >                                   handler);
295 >        try (PoolCleaner cleaner = cleaner(p)) {
296 >            assertSame(handler, p.getRejectedExecutionHandler());
297 >        }
298      }
299  
300      /**
# Line 303 | Line 306 | public class ThreadPoolExecutorTest exte
306              new ThreadPoolExecutor(1, 2,
307                                     LONG_DELAY_MS, MILLISECONDS,
308                                     new ArrayBlockingQueue<Runnable>(10));
309 <        RejectedExecutionHandler h = new NoOpREHandler();
310 <        p.setRejectedExecutionHandler(h);
311 <        assertSame(h, p.getRejectedExecutionHandler());
312 <        joinPool(p);
309 >        try (PoolCleaner cleaner = cleaner(p)) {
310 >            RejectedExecutionHandler handler = new NoOpREHandler();
311 >            p.setRejectedExecutionHandler(handler);
312 >            assertSame(handler, p.getRejectedExecutionHandler());
313 >        }
314      }
315  
316      /**
# Line 317 | Line 321 | public class ThreadPoolExecutorTest exte
321              new ThreadPoolExecutor(1, 2,
322                                     LONG_DELAY_MS, MILLISECONDS,
323                                     new ArrayBlockingQueue<Runnable>(10));
324 <        try {
325 <            p.setRejectedExecutionHandler(null);
326 <            shouldThrow();
327 <        } catch (NullPointerException success) {
328 <        } finally {
325 <            joinPool(p);
324 >        try (PoolCleaner cleaner = cleaner(p)) {
325 >            try {
326 >                p.setRejectedExecutionHandler(null);
327 >                shouldThrow();
328 >            } catch (NullPointerException success) {}
329          }
330      }
331  
# Line 336 | Line 339 | public class ThreadPoolExecutorTest exte
339              new ThreadPoolExecutor(THREADS, THREADS,
340                                     LONG_DELAY_MS, MILLISECONDS,
341                                     new ArrayBlockingQueue<Runnable>(10));
342 <        final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
343 <        final CountDownLatch done = new CountDownLatch(1);
344 <        try {
342 >        try (PoolCleaner cleaner = cleaner(p)) {
343 >            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
344 >            final CountDownLatch done = new CountDownLatch(1);
345              assertEquals(0, p.getLargestPoolSize());
346              for (int i = 0; i < THREADS; i++)
347                  p.execute(new CheckedRunnable() {
# Line 347 | Line 350 | public class ThreadPoolExecutorTest exte
350                          done.await();
351                          assertEquals(THREADS, p.getLargestPoolSize());
352                      }});
353 <            assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS));
351 <            assertEquals(THREADS, p.getLargestPoolSize());
352 <        } finally {
353 <            done.countDown();
354 <            joinPool(p);
353 >            assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
354              assertEquals(THREADS, p.getLargestPoolSize());
355 +            done.countDown();   // release pool
356          }
357 +        assertEquals(THREADS, p.getLargestPoolSize());
358      }
359  
360      /**
# Line 365 | Line 366 | public class ThreadPoolExecutorTest exte
366              new ThreadPoolExecutor(2, 3,
367                                     LONG_DELAY_MS, MILLISECONDS,
368                                     new ArrayBlockingQueue<Runnable>(10));
369 <        assertEquals(3, p.getMaximumPoolSize());
370 <        joinPool(p);
369 >        try (PoolCleaner cleaner = cleaner(p)) {
370 >            assertEquals(3, p.getMaximumPoolSize());
371 >            p.setMaximumPoolSize(5);
372 >            assertEquals(5, p.getMaximumPoolSize());
373 >            p.setMaximumPoolSize(4);
374 >            assertEquals(4, p.getMaximumPoolSize());
375 >        }
376      }
377  
378      /**
# Line 378 | Line 384 | public class ThreadPoolExecutorTest exte
384              new ThreadPoolExecutor(1, 1,
385                                     LONG_DELAY_MS, MILLISECONDS,
386                                     new ArrayBlockingQueue<Runnable>(10));
387 <        final CountDownLatch threadStarted = new CountDownLatch(1);
388 <        final CountDownLatch done = new CountDownLatch(1);
389 <        try {
387 >        try (PoolCleaner cleaner = cleaner(p)) {
388 >            final CountDownLatch threadStarted = new CountDownLatch(1);
389 >            final CountDownLatch done = new CountDownLatch(1);
390              assertEquals(0, p.getPoolSize());
391              p.execute(new CheckedRunnable() {
392                  public void realRun() throws InterruptedException {
# Line 388 | Line 394 | public class ThreadPoolExecutorTest exte
394                      assertEquals(1, p.getPoolSize());
395                      done.await();
396                  }});
397 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
397 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
398              assertEquals(1, p.getPoolSize());
399 <        } finally {
394 <            done.countDown();
395 <            joinPool(p);
399 >            done.countDown();   // release pool
400          }
401      }
402  
# Line 414 | Line 418 | public class ThreadPoolExecutorTest exte
418                      assertEquals(1, p.getTaskCount());
419                      done.await();
420                  }});
421 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
421 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
422              assertEquals(1, p.getTaskCount());
423          } finally {
424              done.countDown();
# Line 484 | Line 488 | public class ThreadPoolExecutorTest exte
488                      threadStarted.countDown();
489                      done.await();
490                  }});
491 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
491 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
492              assertFalse(p.isTerminating());
493              done.countDown();
494          } finally {
# Line 512 | Line 516 | public class ThreadPoolExecutorTest exte
516                      threadStarted.countDown();
517                      done.await();
518                  }});
519 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
519 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
520              assertFalse(p.isTerminating());
521              done.countDown();
522          } finally {
# Line 547 | Line 551 | public class ThreadPoolExecutorTest exte
551                  tasks[i] = new FutureTask(task);
552                  p.execute(tasks[i]);
553              }
554 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
554 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
555              assertSame(q, p.getQueue());
556              assertFalse(q.contains(tasks[0]));
557              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 579 | Line 583 | public class ThreadPoolExecutorTest exte
583                      }};
584                  p.execute(tasks[i]);
585              }
586 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
586 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
587              assertFalse(p.remove(tasks[0]));
588              assertTrue(q.contains(tasks[4]));
589              assertTrue(q.contains(tasks[3]));
# Line 618 | Line 622 | public class ThreadPoolExecutorTest exte
622                  tasks[i] = new FutureTask(task);
623                  p.execute(tasks[i]);
624              }
625 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
625 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
626              assertEquals(tasks.length, p.getTaskCount());
627              assertEquals(tasks.length - 1, q.size());
628              assertEquals(1L, p.getActiveCount());
# Line 1040 | Line 1044 | public class ThreadPoolExecutorTest exte
1044                      p.submit(task).get();
1045                  }});
1046  
1047 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
1047 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
1048              t.interrupt();
1049              awaitTermination(t, MEDIUM_DELAY_MS);
1050          } finally {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines