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.74 by jsr166, Sun Oct 4 01:58:38 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 321 | 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 {
329 <            joinPool(p);
324 >        try (PoolCleaner cleaner = cleaner(p)) {
325 >            try {
326 >                p.setRejectedExecutionHandler(null);
327 >                shouldThrow();
328 >            } catch (NullPointerException success) {}
329          }
330      }
331  
# Line 340 | 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 351 | Line 350 | public class ThreadPoolExecutorTest exte
350                          done.await();
351                          assertEquals(THREADS, p.getLargestPoolSize());
352                      }});
353 <            assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS));
355 <            assertEquals(THREADS, p.getLargestPoolSize());
356 <        } finally {
357 <            done.countDown();
358 <            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 369 | 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 382 | 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 392 | 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 {
398 <            done.countDown();
399 <            joinPool(p);
399 >            done.countDown();   // release pool
400          }
401      }
402  
# Line 418 | 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 488 | 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 516 | 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 551 | 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 583 | 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 622 | 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 1044 | 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