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.46 by jsr166, Sun May 29 13:55:36 2011 UTC vs.
Revision 1.61 by jsr166, Mon Sep 28 02:41:29 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import java.util.concurrent.*;
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 < import java.util.concurrent.atomic.*;
11 < import junit.framework.*;
12 < import java.util.*;
10 > import static java.util.concurrent.TimeUnit.NANOSECONDS;
11 > import static java.util.concurrent.TimeUnit.SECONDS;
12 >
13 > import java.util.ArrayList;
14 > import java.util.List;
15 > import java.util.concurrent.ArrayBlockingQueue;
16 > import java.util.concurrent.BlockingQueue;
17 > import java.util.concurrent.Callable;
18 > import java.util.concurrent.CancellationException;
19 > import java.util.concurrent.CountDownLatch;
20 > import java.util.concurrent.ExecutionException;
21 > import java.util.concurrent.Executors;
22 > import java.util.concurrent.ExecutorService;
23 > import java.util.concurrent.Future;
24 > import java.util.concurrent.FutureTask;
25 > import java.util.concurrent.LinkedBlockingQueue;
26 > import java.util.concurrent.RejectedExecutionException;
27 > import java.util.concurrent.RejectedExecutionHandler;
28 > import java.util.concurrent.SynchronousQueue;
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;
36  
37   public class ThreadPoolExecutorTest extends JSR166TestCase {
38      public static void main(String[] args) {
39 <        junit.textui.TestRunner.run(suite());
39 >        main(suite(), args);
40      }
41      public static Test suite() {
42          return new TestSuite(ThreadPoolExecutorTest.class);
# Line 195 | Line 217 | public class ThreadPoolExecutorTest exte
217              new ThreadPoolExecutor(2, 2,
218                                     1000, MILLISECONDS,
219                                     new ArrayBlockingQueue<Runnable>(10));
220 <        assertEquals(1, p.getKeepAliveTime(TimeUnit.SECONDS));
220 >        assertEquals(1, p.getKeepAliveTime(SECONDS));
221          joinPool(p);
222      }
223  
# Line 402 | Line 424 | public class ThreadPoolExecutorTest exte
424      }
425  
426      /**
427 +     * awaitTermination on a non-shutdown pool times out
428 +     */
429 +    public void testAwaitTermination_timesOut() throws InterruptedException {
430 +        final ThreadPoolExecutor p =
431 +            new ThreadPoolExecutor(1, 1,
432 +                                   LONG_DELAY_MS, MILLISECONDS,
433 +                                   new ArrayBlockingQueue<Runnable>(10));
434 +        assertFalse(p.isTerminated());
435 +        assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
436 +        assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
437 +        assertFalse(p.awaitTermination(-1L, NANOSECONDS));
438 +        assertFalse(p.awaitTermination(-1L, MILLISECONDS));
439 +        assertFalse(p.awaitTermination(0L, NANOSECONDS));
440 +        assertFalse(p.awaitTermination(0L, MILLISECONDS));
441 +        long timeoutNanos = 999999L;
442 +        long startTime = System.nanoTime();
443 +        assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
444 +        assertTrue(System.nanoTime() - startTime >= timeoutNanos);
445 +        assertFalse(p.isTerminated());
446 +        startTime = System.nanoTime();
447 +        long timeoutMillis = timeoutMillis();
448 +        assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
449 +        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
450 +        assertFalse(p.isTerminated());
451 +        p.shutdown();
452 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
453 +        assertTrue(p.isTerminated());
454 +    }
455 +
456 +    /**
457       * isTerminated is false before termination, true after
458       */
459      public void testIsTerminated() throws InterruptedException {
# Line 573 | Line 625 | public class ThreadPoolExecutorTest exte
625      }
626  
627      /**
628 <     * shutdownNow returns a list containing tasks that were not run
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++)
586 <                p.execute(new MediumPossiblyInterruptedRunnable());
587 <        }
588 <        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(l.size() <= 4);
657 >        assertTrue(p.getQueue().isEmpty());
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
# Line 601 | Line 668 | public class ThreadPoolExecutorTest exte
668       */
669      public void testConstructor1() {
670          try {
671 <            new ThreadPoolExecutor(-1, 1,
605 <                                   LONG_DELAY_MS, MILLISECONDS,
671 >            new ThreadPoolExecutor(-1, 1, 1L, SECONDS,
672                                     new ArrayBlockingQueue<Runnable>(10));
673              shouldThrow();
674          } catch (IllegalArgumentException success) {}
# Line 613 | Line 679 | public class ThreadPoolExecutorTest exte
679       */
680      public void testConstructor2() {
681          try {
682 <            new ThreadPoolExecutor(1, -1,
617 <                                   LONG_DELAY_MS, MILLISECONDS,
682 >            new ThreadPoolExecutor(1, -1, 1L, SECONDS,
683                                     new ArrayBlockingQueue<Runnable>(10));
684              shouldThrow();
685          } catch (IllegalArgumentException success) {}
# Line 625 | Line 690 | public class ThreadPoolExecutorTest exte
690       */
691      public void testConstructor3() {
692          try {
693 <            new ThreadPoolExecutor(1, 0,
629 <                                   LONG_DELAY_MS, MILLISECONDS,
693 >            new ThreadPoolExecutor(1, 0, 1L, SECONDS,
694                                     new ArrayBlockingQueue<Runnable>(10));
695              shouldThrow();
696          } catch (IllegalArgumentException success) {}
# Line 637 | Line 701 | public class ThreadPoolExecutorTest exte
701       */
702      public void testConstructor4() {
703          try {
704 <            new ThreadPoolExecutor(1, 2,
641 <                                   -1L, MILLISECONDS,
704 >            new ThreadPoolExecutor(1, 2, -1L, SECONDS,
705                                     new ArrayBlockingQueue<Runnable>(10));
706              shouldThrow();
707          } catch (IllegalArgumentException success) {}
# Line 649 | Line 712 | public class ThreadPoolExecutorTest exte
712       */
713      public void testConstructor5() {
714          try {
715 <            new ThreadPoolExecutor(2, 1,
653 <                                   LONG_DELAY_MS, MILLISECONDS,
715 >            new ThreadPoolExecutor(2, 1, 1L, SECONDS,
716                                     new ArrayBlockingQueue<Runnable>(10));
717              shouldThrow();
718          } catch (IllegalArgumentException success) {}
# Line 661 | Line 723 | public class ThreadPoolExecutorTest exte
723       */
724      public void testConstructorNullPointerException() {
725          try {
726 <            new ThreadPoolExecutor(1, 2,
665 <                                   LONG_DELAY_MS, MILLISECONDS,
726 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
727                                     (BlockingQueue) null);
728              shouldThrow();
729          } catch (NullPointerException success) {}
# Line 673 | Line 734 | public class ThreadPoolExecutorTest exte
734       */
735      public void testConstructor6() {
736          try {
737 <            new ThreadPoolExecutor(-1, 1,
677 <                                   LONG_DELAY_MS, MILLISECONDS,
737 >            new ThreadPoolExecutor(-1, 1, 1L, SECONDS,
738                                     new ArrayBlockingQueue<Runnable>(10),
739                                     new SimpleThreadFactory());
740              shouldThrow();
# Line 686 | Line 746 | public class ThreadPoolExecutorTest exte
746       */
747      public void testConstructor7() {
748          try {
749 <            new ThreadPoolExecutor(1, -1,
690 <                                   LONG_DELAY_MS, MILLISECONDS,
749 >            new ThreadPoolExecutor(1, -1, 1L, SECONDS,
750                                     new ArrayBlockingQueue<Runnable>(10),
751                                     new SimpleThreadFactory());
752              shouldThrow();
# Line 699 | Line 758 | public class ThreadPoolExecutorTest exte
758       */
759      public void testConstructor8() {
760          try {
761 <            new ThreadPoolExecutor(1, 0,
703 <                                   LONG_DELAY_MS, MILLISECONDS,
761 >            new ThreadPoolExecutor(1, 0, 1L, SECONDS,
762                                     new ArrayBlockingQueue<Runnable>(10),
763                                     new SimpleThreadFactory());
764              shouldThrow();
# Line 712 | Line 770 | public class ThreadPoolExecutorTest exte
770       */
771      public void testConstructor9() {
772          try {
773 <            new ThreadPoolExecutor(1, 2,
716 <                                   -1L, MILLISECONDS,
773 >            new ThreadPoolExecutor(1, 2, -1L, SECONDS,
774                                     new ArrayBlockingQueue<Runnable>(10),
775                                     new SimpleThreadFactory());
776              shouldThrow();
# Line 725 | Line 782 | public class ThreadPoolExecutorTest exte
782       */
783      public void testConstructor10() {
784          try {
785 <            new ThreadPoolExecutor(2, 1,
729 <                                   LONG_DELAY_MS, MILLISECONDS,
785 >            new ThreadPoolExecutor(2, 1, 1L, SECONDS,
786                                     new ArrayBlockingQueue<Runnable>(10),
787                                     new SimpleThreadFactory());
788              shouldThrow();
# Line 738 | Line 794 | public class ThreadPoolExecutorTest exte
794       */
795      public void testConstructorNullPointerException2() {
796          try {
797 <            new ThreadPoolExecutor(1, 2,
742 <                                   LONG_DELAY_MS, MILLISECONDS,
797 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
798                                     (BlockingQueue) null,
799                                     new SimpleThreadFactory());
800              shouldThrow();
# Line 751 | Line 806 | public class ThreadPoolExecutorTest exte
806       */
807      public void testConstructorNullPointerException3() {
808          try {
809 <            new ThreadPoolExecutor(1, 2,
755 <                                   LONG_DELAY_MS, MILLISECONDS,
809 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
810                                     new ArrayBlockingQueue<Runnable>(10),
811                                     (ThreadFactory) null);
812              shouldThrow();
# Line 764 | Line 818 | public class ThreadPoolExecutorTest exte
818       */
819      public void testConstructor11() {
820          try {
821 <            new ThreadPoolExecutor(-1, 1,
768 <                                   LONG_DELAY_MS, MILLISECONDS,
821 >            new ThreadPoolExecutor(-1, 1, 1L, SECONDS,
822                                     new ArrayBlockingQueue<Runnable>(10),
823                                     new NoOpREHandler());
824              shouldThrow();
# Line 777 | Line 830 | public class ThreadPoolExecutorTest exte
830       */
831      public void testConstructor12() {
832          try {
833 <            new ThreadPoolExecutor(1, -1,
781 <                                   LONG_DELAY_MS, MILLISECONDS,
833 >            new ThreadPoolExecutor(1, -1, 1L, SECONDS,
834                                     new ArrayBlockingQueue<Runnable>(10),
835                                     new NoOpREHandler());
836              shouldThrow();
# Line 790 | Line 842 | public class ThreadPoolExecutorTest exte
842       */
843      public void testConstructor13() {
844          try {
845 <            new ThreadPoolExecutor(1, 0,
794 <                                   LONG_DELAY_MS, MILLISECONDS,
845 >            new ThreadPoolExecutor(1, 0, 1L, SECONDS,
846                                     new ArrayBlockingQueue<Runnable>(10),
847                                     new NoOpREHandler());
848              shouldThrow();
# Line 803 | Line 854 | public class ThreadPoolExecutorTest exte
854       */
855      public void testConstructor14() {
856          try {
857 <            new ThreadPoolExecutor(1, 2,
807 <                                   -1L, MILLISECONDS,
857 >            new ThreadPoolExecutor(1, 2, -1L, SECONDS,
858                                     new ArrayBlockingQueue<Runnable>(10),
859                                     new NoOpREHandler());
860              shouldThrow();
# Line 816 | Line 866 | public class ThreadPoolExecutorTest exte
866       */
867      public void testConstructor15() {
868          try {
869 <            new ThreadPoolExecutor(2, 1,
820 <                                   LONG_DELAY_MS, MILLISECONDS,
869 >            new ThreadPoolExecutor(2, 1, 1L, SECONDS,
870                                     new ArrayBlockingQueue<Runnable>(10),
871                                     new NoOpREHandler());
872              shouldThrow();
# Line 829 | Line 878 | public class ThreadPoolExecutorTest exte
878       */
879      public void testConstructorNullPointerException4() {
880          try {
881 <            new ThreadPoolExecutor(1, 2,
833 <                                   LONG_DELAY_MS, MILLISECONDS,
881 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
882                                     (BlockingQueue) null,
883                                     new NoOpREHandler());
884              shouldThrow();
# Line 842 | Line 890 | public class ThreadPoolExecutorTest exte
890       */
891      public void testConstructorNullPointerException5() {
892          try {
893 <            new ThreadPoolExecutor(1, 2,
846 <                                   LONG_DELAY_MS, MILLISECONDS,
893 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
894                                     new ArrayBlockingQueue<Runnable>(10),
895                                     (RejectedExecutionHandler) null);
896              shouldThrow();
# Line 855 | Line 902 | public class ThreadPoolExecutorTest exte
902       */
903      public void testConstructor16() {
904          try {
905 <            new ThreadPoolExecutor(-1, 1,
859 <                                   LONG_DELAY_MS, MILLISECONDS,
905 >            new ThreadPoolExecutor(-1, 1, 1L, SECONDS,
906                                     new ArrayBlockingQueue<Runnable>(10),
907                                     new SimpleThreadFactory(),
908                                     new NoOpREHandler());
# Line 869 | Line 915 | public class ThreadPoolExecutorTest exte
915       */
916      public void testConstructor17() {
917          try {
918 <            new ThreadPoolExecutor(1, -1,
873 <                                   LONG_DELAY_MS, MILLISECONDS,
918 >            new ThreadPoolExecutor(1, -1, 1L, SECONDS,
919                                     new ArrayBlockingQueue<Runnable>(10),
920                                     new SimpleThreadFactory(),
921                                     new NoOpREHandler());
# Line 883 | Line 928 | public class ThreadPoolExecutorTest exte
928       */
929      public void testConstructor18() {
930          try {
931 <            new ThreadPoolExecutor(1, 0,
887 <                                   LONG_DELAY_MS, MILLISECONDS,
931 >            new ThreadPoolExecutor(1, 0, 1L, SECONDS,
932                                     new ArrayBlockingQueue<Runnable>(10),
933                                     new SimpleThreadFactory(),
934                                     new NoOpREHandler());
# Line 897 | Line 941 | public class ThreadPoolExecutorTest exte
941       */
942      public void testConstructor19() {
943          try {
944 <            new ThreadPoolExecutor(1, 2,
901 <                                   -1L, MILLISECONDS,
944 >            new ThreadPoolExecutor(1, 2, -1L, SECONDS,
945                                     new ArrayBlockingQueue<Runnable>(10),
946                                     new SimpleThreadFactory(),
947                                     new NoOpREHandler());
# Line 911 | Line 954 | public class ThreadPoolExecutorTest exte
954       */
955      public void testConstructor20() {
956          try {
957 <            new ThreadPoolExecutor(2, 1,
915 <                                   LONG_DELAY_MS, MILLISECONDS,
957 >            new ThreadPoolExecutor(2, 1, 1L, SECONDS,
958                                     new ArrayBlockingQueue<Runnable>(10),
959                                     new SimpleThreadFactory(),
960                                     new NoOpREHandler());
# Line 925 | Line 967 | public class ThreadPoolExecutorTest exte
967       */
968      public void testConstructorNullPointerException6() {
969          try {
970 <            new ThreadPoolExecutor(1, 2,
929 <                                   LONG_DELAY_MS, MILLISECONDS,
970 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
971                                     (BlockingQueue) null,
972                                     new SimpleThreadFactory(),
973                                     new NoOpREHandler());
# Line 939 | Line 980 | public class ThreadPoolExecutorTest exte
980       */
981      public void testConstructorNullPointerException7() {
982          try {
983 <            new ThreadPoolExecutor(1, 2,
943 <                                   LONG_DELAY_MS, MILLISECONDS,
983 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
984                                     new ArrayBlockingQueue<Runnable>(10),
985                                     new SimpleThreadFactory(),
986                                     (RejectedExecutionHandler) null);
# Line 953 | Line 993 | public class ThreadPoolExecutorTest exte
993       */
994      public void testConstructorNullPointerException8() {
995          try {
996 <            new ThreadPoolExecutor(1, 2,
957 <                                   LONG_DELAY_MS, MILLISECONDS,
996 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
997                                     new ArrayBlockingQueue<Runnable>(10),
998                                     (ThreadFactory) null,
999                                     new NoOpREHandler());
# Line 968 | Line 1007 | public class ThreadPoolExecutorTest exte
1007      public void testInterruptedSubmit() throws InterruptedException {
1008          final ThreadPoolExecutor p =
1009              new ThreadPoolExecutor(1, 1,
1010 <                                   60, TimeUnit.SECONDS,
1010 >                                   60, SECONDS,
1011                                     new ArrayBlockingQueue<Runnable>(10));
1012  
1013          final CountDownLatch threadStarted = new CountDownLatch(1);
# Line 1242 | Line 1281 | public class ThreadPoolExecutorTest exte
1281       */
1282      public void testExecuteNull() {
1283          ThreadPoolExecutor p =
1284 <            new ThreadPoolExecutor(1, 2,
1246 <                                   LONG_DELAY_MS, MILLISECONDS,
1284 >            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
1285                                     new ArrayBlockingQueue<Runnable>(10));
1286          try {
1287              p.execute(null);
# Line 1310 | Line 1348 | public class ThreadPoolExecutorTest exte
1348      }
1349  
1350      /**
1351 +     * Configuration changes that allow core pool size greater than
1352 +     * max pool size result in IllegalArgumentException.
1353 +     */
1354 +    public void testPoolSizeInvariants() {
1355 +        ThreadPoolExecutor p =
1356 +            new ThreadPoolExecutor(1, 1,
1357 +                                   LONG_DELAY_MS, MILLISECONDS,
1358 +                                   new ArrayBlockingQueue<Runnable>(10));
1359 +        for (int s = 1; s < 5; s++) {
1360 +            p.setMaximumPoolSize(s);
1361 +            p.setCorePoolSize(s);
1362 +            try {
1363 +                p.setMaximumPoolSize(s - 1);
1364 +                shouldThrow();
1365 +            } catch (IllegalArgumentException success) {}
1366 +            assertEquals(s, p.getCorePoolSize());
1367 +            assertEquals(s, p.getMaximumPoolSize());
1368 +            try {
1369 +                p.setCorePoolSize(s + 1);
1370 +                shouldThrow();
1371 +            } catch (IllegalArgumentException success) {}
1372 +            assertEquals(s, p.getCorePoolSize());
1373 +            assertEquals(s, p.getMaximumPoolSize());
1374 +        }
1375 +        joinPool(p);
1376 +    }
1377 +
1378 +    /**
1379       * setKeepAliveTime throws IllegalArgumentException
1380       * when given a negative value
1381       */
# Line 1345 | Line 1411 | public class ThreadPoolExecutorTest exte
1411          ExtendedTPE p = new ExtendedTPE();
1412          try {
1413              final CountDownLatch done = new CountDownLatch(1);
1414 <            final CheckedRunnable task = new CheckedRunnable() {
1414 >            p.execute(new CheckedRunnable() {
1415                  public void realRun() {
1416                      done.countDown();
1417 <                }};
1352 <            p.execute(task);
1417 >                }});
1418              await(p.afterCalled);
1419              assertEquals(0, done.getCount());
1420              assertTrue(p.afterCalled());
# Line 1844 | Line 1909 | public class ThreadPoolExecutorTest exte
1909                                     LONG_DELAY_MS, MILLISECONDS,
1910                                     new ArrayBlockingQueue<Runnable>(10));
1911          try {
1912 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1913 <            l.add(new StringTask());
1914 <            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1915 <            l.add(new StringTask());
1916 <            List<Future<String>> futures =
1917 <                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1918 <            assertEquals(l.size(), futures.size());
1919 <            for (Future future : futures)
1920 <                assertTrue(future.isDone());
1921 <            assertFalse(futures.get(0).isCancelled());
1922 <            assertTrue(futures.get(1).isCancelled());
1912 >            for (long timeout = timeoutMillis();;) {
1913 >                List<Callable<String>> tasks = new ArrayList<>();
1914 >                tasks.add(new StringTask("0"));
1915 >                tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING));
1916 >                tasks.add(new StringTask("2"));
1917 >                long startTime = System.nanoTime();
1918 >                List<Future<String>> futures =
1919 >                    e.invokeAll(tasks, timeout, MILLISECONDS);
1920 >                assertEquals(tasks.size(), futures.size());
1921 >                assertTrue(millisElapsedSince(startTime) >= timeout);
1922 >                for (Future future : futures)
1923 >                    assertTrue(future.isDone());
1924 >                assertTrue(futures.get(1).isCancelled());
1925 >                try {
1926 >                    assertEquals("0", futures.get(0).get());
1927 >                    assertEquals("2", futures.get(2).get());
1928 >                    break;
1929 >                } catch (CancellationException retryWithLongerTimeout) {
1930 >                    timeout *= 2;
1931 >                    if (timeout >= LONG_DELAY_MS / 2)
1932 >                        fail("expected exactly one task to be cancelled");
1933 >                }
1934 >            }
1935          } finally {
1936              joinPool(e);
1937          }
# Line 1900 | Line 1977 | public class ThreadPoolExecutorTest exte
1977       * allowCoreThreadTimeOut(true) causes idle threads to time out
1978       */
1979      public void testAllowCoreThreadTimeOut_true() throws Exception {
1980 <        long coreThreadTimeOut = SHORT_DELAY_MS;
1980 >        long keepAliveTime = timeoutMillis();
1981          final ThreadPoolExecutor p =
1982              new ThreadPoolExecutor(2, 10,
1983 <                                   coreThreadTimeOut, MILLISECONDS,
1983 >                                   keepAliveTime, MILLISECONDS,
1984                                     new ArrayBlockingQueue<Runnable>(10));
1985          final CountDownLatch threadStarted = new CountDownLatch(1);
1986          try {
# Line 1914 | Line 1991 | public class ThreadPoolExecutorTest exte
1991                      assertEquals(1, p.getPoolSize());
1992                  }});
1993              await(threadStarted);
1994 <            delay(coreThreadTimeOut);
1994 >            delay(keepAliveTime);
1995              long startTime = System.nanoTime();
1996              while (p.getPoolSize() > 0
1997                     && millisElapsedSince(startTime) < LONG_DELAY_MS)
# Line 1930 | Line 2007 | public class ThreadPoolExecutorTest exte
2007       * allowCoreThreadTimeOut(false) causes idle threads not to time out
2008       */
2009      public void testAllowCoreThreadTimeOut_false() throws Exception {
2010 <        long coreThreadTimeOut = SHORT_DELAY_MS;
2010 >        long keepAliveTime = timeoutMillis();
2011          final ThreadPoolExecutor p =
2012              new ThreadPoolExecutor(2, 10,
2013 <                                   coreThreadTimeOut, MILLISECONDS,
2013 >                                   keepAliveTime, MILLISECONDS,
2014                                     new ArrayBlockingQueue<Runnable>(10));
2015          final CountDownLatch threadStarted = new CountDownLatch(1);
2016          try {
# Line 1943 | Line 2020 | public class ThreadPoolExecutorTest exte
2020                      threadStarted.countDown();
2021                      assertTrue(p.getPoolSize() >= 1);
2022                  }});
2023 <            delay(2 * coreThreadTimeOut);
2023 >            delay(2 * keepAliveTime);
2024              assertTrue(p.getPoolSize() >= 1);
2025          } finally {
2026              joinPool(p);
# Line 1962 | Line 2039 | public class ThreadPoolExecutorTest exte
2039                  done.countDown();
2040              }};
2041          final ThreadPoolExecutor p =
2042 <            new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS,
2042 >            new ThreadPoolExecutor(1, 30,
2043 >                                   60, SECONDS,
2044                                     new ArrayBlockingQueue(30));
2045          try {
2046              for (int i = 0; i < nTasks; ++i) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines