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.60 by jsr166, Sun Sep 27 18:50:50 2015 UTC vs.
Revision 1.61 by jsr166, Mon Sep 28 02:41:29 2015 UTC

# Line 29 | Line 29 | import java.util.concurrent.SynchronousQ
29   import java.util.concurrent.ThreadFactory;
30   import java.util.concurrent.ThreadPoolExecutor;
31   import java.util.concurrent.TimeUnit;
32 + import java.util.concurrent.atomic.AtomicInteger;
33  
34   import junit.framework.Test;
35   import junit.framework.TestSuite;
# Line 627 | Line 628 | public class ThreadPoolExecutorTest exte
628       * shutdownNow returns a list containing tasks that were not run,
629       * and those tasks are drained from the queue
630       */
631 <    public void testShutdownNow() {
631 >    public void testShutdownNow() throws InterruptedException {
632 >        final int poolSize = 2;
633 >        final int count = 5;
634 >        final AtomicInteger ran = new AtomicInteger(0);
635          final ThreadPoolExecutor p =
636 <            new ThreadPoolExecutor(1, 1,
636 >            new ThreadPoolExecutor(poolSize, poolSize,
637                                     LONG_DELAY_MS, MILLISECONDS,
638                                     new ArrayBlockingQueue<Runnable>(10));
639 <        List l;
640 <        try {
641 <            for (int i = 0; i < 5; i++)
638 <                p.execute(new MediumPossiblyInterruptedRunnable());
639 <        }
640 <        finally {
639 >        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
640 >        CheckedRunnable waiter = new CheckedRunnable() { public void realRun() {
641 >            threadsStarted.countDown();
642              try {
643 <                l = p.shutdownNow();
644 <            } catch (SecurityException ok) { return; }
643 >                MILLISECONDS.sleep(2 * LONG_DELAY_MS);
644 >            } catch (InterruptedException success) {}
645 >            ran.getAndIncrement();
646 >        }};
647 >        for (int i = 0; i < count; i++)
648 >            p.execute(waiter);
649 >        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
650 >        final List<Runnable> queuedTasks;
651 >        try {
652 >            queuedTasks = p.shutdownNow();
653 >        } catch (SecurityException ok) {
654 >            return; // Allowed in case test doesn't have privs
655          }
656          assertTrue(p.isShutdown());
657          assertTrue(p.getQueue().isEmpty());
658 <        assertTrue(l.size() <= 4);
658 >        assertEquals(count - poolSize, queuedTasks.size());
659 >        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
660 >        assertTrue(p.isTerminated());
661 >        assertEquals(poolSize, ran.get());
662      }
663  
664      // Exception Tests

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines