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.39 by jsr166, Mon Sep 14 03:27:11 2015 UTC vs.
Revision 1.43 by jsr166, Mon Sep 28 08:23:49 2015 UTC

# Line 30 | Line 30 | import java.util.concurrent.ThreadFactor
30   import java.util.concurrent.ThreadPoolExecutor;
31   import java.util.concurrent.TimeoutException;
32   import java.util.concurrent.TimeUnit;
33 + import java.util.concurrent.atomic.AtomicInteger;
34   import java.util.concurrent.locks.Condition;
35   import java.util.concurrent.locks.ReentrantLock;
36  
# Line 699 | Line 700 | public class ThreadPoolExecutorSubclassT
700      }
701  
702      /**
703 <     * shutdownNow returns a list containing tasks that were not run
703 >     * shutdownNow returns a list containing tasks that were not run,
704 >     * and those tasks are drained from the queue
705       */
706 <    public void testShutdownNow() {
707 <        ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
708 <        List l;
709 <        try {
710 <            for (int i = 0; i < 5; i++)
711 <                p.execute(new MediumPossiblyInterruptedRunnable());
712 <        }
713 <        finally {
706 >    public void testShutdownNow() throws InterruptedException {
707 >        final int poolSize = 2;
708 >        final int count = 5;
709 >        final AtomicInteger ran = new AtomicInteger(0);
710 >        ThreadPoolExecutor p =
711 >            new CustomTPE(poolSize, poolSize, LONG_DELAY_MS, MILLISECONDS,
712 >                          new ArrayBlockingQueue<Runnable>(10));
713 >        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
714 >        Runnable waiter = new CheckedRunnable() { public void realRun() {
715 >            threadsStarted.countDown();
716              try {
717 <                l = p.shutdownNow();
718 <            } catch (SecurityException ok) { return; }
717 >                MILLISECONDS.sleep(2 * LONG_DELAY_MS);
718 >            } catch (InterruptedException success) {}
719 >            ran.getAndIncrement();
720 >        }};
721 >        for (int i = 0; i < count; i++)
722 >            p.execute(waiter);
723 >        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
724 >        assertEquals(poolSize, p.getActiveCount());
725 >        assertEquals(0, p.getCompletedTaskCount());
726 >        final List<Runnable> queuedTasks;
727 >        try {
728 >            queuedTasks = p.shutdownNow();
729 >        } catch (SecurityException ok) {
730 >            return; // Allowed in case test doesn't have privs
731          }
732          assertTrue(p.isShutdown());
733 <        assertTrue(l.size() <= 4);
733 >        assertTrue(p.getQueue().isEmpty());
734 >        assertEquals(count - poolSize, queuedTasks.size());
735 >        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
736 >        assertTrue(p.isTerminated());
737 >        assertEquals(poolSize, ran.get());
738 >        assertEquals(poolSize, p.getCompletedTaskCount());
739      }
740  
741      // Exception Tests

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines