ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ScheduledExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.51 by jsr166, Sat Apr 25 04:55:31 2015 UTC vs.
Revision 1.53 by jsr166, Sun Sep 27 18:50:50 2015 UTC

# Line 12 | Line 12 | import java.util.ArrayList;
12   import java.util.List;
13   import java.util.concurrent.BlockingQueue;
14   import java.util.concurrent.Callable;
15 + import java.util.concurrent.CancellationException;
16   import java.util.concurrent.CountDownLatch;
17   import java.util.concurrent.ExecutionException;
18   import java.util.concurrent.Executors;
# Line 650 | Line 651 | public class ScheduledExecutorTest exten
651      }
652  
653      /**
654 <     * shutdownNow returns a list containing tasks that were not run
654 >     * shutdownNow returns a list containing tasks that were not run,
655 >     * and those tasks are drained from the queue
656       */
657      public void testShutdownNow() {
658          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
# Line 660 | Line 662 | public class ScheduledExecutorTest exten
662          try {
663              List<Runnable> l = p.shutdownNow();
664              assertTrue(p.isShutdown());
665 +            assertTrue(p.getQueue().isEmpty());
666              assertEquals(5, l.size());
667          } catch (SecurityException ok) {
668              // Allowed in case test doesn't have privs
# Line 1186 | Line 1189 | public class ScheduledExecutorTest exten
1189      public void testTimedInvokeAll6() throws Exception {
1190          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1191          try {
1192 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1193 <            l.add(new StringTask());
1194 <            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1195 <            l.add(new StringTask());
1196 <            List<Future<String>> futures =
1197 <                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1198 <            assertEquals(l.size(), futures.size());
1199 <            for (Future future : futures)
1200 <                assertTrue(future.isDone());
1201 <            assertFalse(futures.get(0).isCancelled());
1202 <            assertTrue(futures.get(1).isCancelled());
1192 >            for (long timeout = timeoutMillis();;) {
1193 >                List<Callable<String>> tasks = new ArrayList<>();
1194 >                tasks.add(new StringTask("0"));
1195 >                tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING));
1196 >                tasks.add(new StringTask("2"));
1197 >                long startTime = System.nanoTime();
1198 >                List<Future<String>> futures =
1199 >                    e.invokeAll(tasks, timeout, MILLISECONDS);
1200 >                assertEquals(tasks.size(), futures.size());
1201 >                assertTrue(millisElapsedSince(startTime) >= timeout);
1202 >                for (Future future : futures)
1203 >                    assertTrue(future.isDone());
1204 >                assertTrue(futures.get(1).isCancelled());
1205 >                try {
1206 >                    assertEquals("0", futures.get(0).get());
1207 >                    assertEquals("2", futures.get(2).get());
1208 >                    break;
1209 >                } catch (CancellationException retryWithLongerTimeout) {
1210 >                    timeout *= 2;
1211 >                    if (timeout >= LONG_DELAY_MS / 2)
1212 >                        fail("expected exactly one task to be cancelled");
1213 >                }
1214 >            }
1215          } finally {
1216              joinPool(e);
1217          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines