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

Comparing jsr166/src/test/tck/ScheduledExecutorSubclassTest.java (file contents):
Revision 1.51 by jsr166, Tue Oct 6 05:03:23 2015 UTC vs.
Revision 1.59 by jsr166, Sun Oct 25 02:58:25 2015 UTC

# Line 220 | Line 220 | public class ScheduledExecutorSubclassTe
220                      normalizedTime <= cycles)
221                      return;
222              }
223 <            throw new AssertionError("unexpected execution rate");
223 >            fail("unexpected execution rate");
224          }
225      }
226  
# Line 246 | Line 246 | public class ScheduledExecutorSubclassTe
246                      normalizedTime <= cycles)
247                      return;
248              }
249 <            throw new AssertionError("unexpected execution rate");
249 >            fail("unexpected execution rate");
250          }
251      }
252  
# Line 437 | Line 437 | public class ScheduledExecutorSubclassTe
437                          await(done);
438                          assertEquals(THREADS, p.getLargestPoolSize());
439                      }});
440 <            assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
440 >            await(threadsStarted);
441              assertEquals(THREADS, p.getLargestPoolSize());
442          }
443          assertEquals(THREADS, p.getLargestPoolSize());
# Line 587 | Line 587 | public class ScheduledExecutorSubclassTe
587                      threadStarted.countDown();
588                      await(done);
589                  }});
590 <            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
590 >            await(threadStarted);
591              assertFalse(p.isTerminating());
592              done.countDown();
593              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 601 | Line 601 | public class ScheduledExecutorSubclassTe
601       * getQueue returns the work queue, which contains queued tasks
602       */
603      public void testGetQueue() throws InterruptedException {
604 +        final CountDownLatch done = new CountDownLatch(1);
605          final ScheduledThreadPoolExecutor p = new CustomExecutor(1);
606 <        try (PoolCleaner cleaner = cleaner(p)) {
606 >        try (PoolCleaner cleaner = cleaner(p, done)) {
607              final CountDownLatch threadStarted = new CountDownLatch(1);
607            final CountDownLatch done = new CountDownLatch(1);
608              ScheduledFuture[] tasks = new ScheduledFuture[5];
609              for (int i = 0; i < tasks.length; i++) {
610                  Runnable r = new CheckedRunnable() {
611                      public void realRun() throws InterruptedException {
612                          threadStarted.countDown();
613 <                        done.await();
613 >                        await(done);
614                      }};
615                  tasks[i] = p.schedule(r, 1, MILLISECONDS);
616              }
617 <            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
617 >            await(threadStarted);
618              BlockingQueue<Runnable> q = p.getQueue();
619              assertTrue(q.contains(tasks[tasks.length - 1]));
620              assertFalse(q.contains(tasks[0]));
621            done.countDown();
621          }
622      }
623  
# Line 626 | Line 625 | public class ScheduledExecutorSubclassTe
625       * remove(task) removes queued task, and fails to remove active task
626       */
627      public void testRemove() throws InterruptedException {
628 +        final CountDownLatch done = new CountDownLatch(1);
629          final ScheduledThreadPoolExecutor p = new CustomExecutor(1);
630 <        try (PoolCleaner cleaner = cleaner(p)) {
630 >        try (PoolCleaner cleaner = cleaner(p, done)) {
631              ScheduledFuture[] tasks = new ScheduledFuture[5];
632              final CountDownLatch threadStarted = new CountDownLatch(1);
633            final CountDownLatch done = new CountDownLatch(1);
633              for (int i = 0; i < tasks.length; i++) {
634                  Runnable r = new CheckedRunnable() {
635                      public void realRun() throws InterruptedException {
636                          threadStarted.countDown();
637 <                        done.await();
637 >                        await(done);
638                      }};
639                  tasks[i] = p.schedule(r, 1, MILLISECONDS);
640              }
641 <            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
641 >            await(threadStarted);
642              BlockingQueue<Runnable> q = p.getQueue();
643              assertFalse(p.remove((Runnable)tasks[0]));
644              assertTrue(q.contains((Runnable)tasks[4]));
# Line 650 | Line 649 | public class ScheduledExecutorSubclassTe
649              assertTrue(q.contains((Runnable)tasks[3]));
650              assertTrue(p.remove((Runnable)tasks[3]));
651              assertFalse(q.contains((Runnable)tasks[3]));
653            done.countDown();
652          }
653      }
654  
# Line 702 | Line 700 | public class ScheduledExecutorSubclassTe
700          }};
701          for (int i = 0; i < count; i++)
702              p.execute(waiter);
703 <        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
703 >        await(threadsStarted);
704          assertEquals(poolSize, p.getActiveCount());
705          assertEquals(0, p.getCompletedTaskCount());
706          final List<Runnable> queuedTasks;
# Line 1099 | Line 1097 | public class ScheduledExecutorSubclassTe
1097      public void testTimedInvokeAny4() throws Exception {
1098          final ExecutorService e = new CustomExecutor(2);
1099          try (PoolCleaner cleaner = cleaner(e)) {
1100 +            long startTime = System.nanoTime();
1101              List<Callable<String>> l = new ArrayList<Callable<String>>();
1102              l.add(new NPETask());
1103              try {
1104 <                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1104 >                e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
1105                  shouldThrow();
1106              } catch (ExecutionException success) {
1107                  assertTrue(success.getCause() instanceof NullPointerException);
1108              }
1109 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1110          }
1111      }
1112  
# Line 1116 | Line 1116 | public class ScheduledExecutorSubclassTe
1116      public void testTimedInvokeAny5() throws Exception {
1117          final ExecutorService e = new CustomExecutor(2);
1118          try (PoolCleaner cleaner = cleaner(e)) {
1119 +            long startTime = System.nanoTime();
1120              List<Callable<String>> l = new ArrayList<Callable<String>>();
1121              l.add(new StringTask());
1122              l.add(new StringTask());
1123 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1123 >            String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
1124              assertSame(TEST_STRING, result);
1125 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1126          }
1127      }
1128  
# Line 1220 | Line 1222 | public class ScheduledExecutorSubclassTe
1222       * timed invokeAll(c) cancels tasks not completed by timeout
1223       */
1224      public void testTimedInvokeAll6() throws Exception {
1225 <        final ExecutorService e = new CustomExecutor(2);
1226 <        try (PoolCleaner cleaner = cleaner(e)) {
1227 <            for (long timeout = timeoutMillis();;) {
1225 >        for (long timeout = timeoutMillis();;) {
1226 >            final CountDownLatch done = new CountDownLatch(1);
1227 >            final Callable<String> waiter = new CheckedCallable<String>() {
1228 >                public String realCall() {
1229 >                    try { done.await(LONG_DELAY_MS, MILLISECONDS); }
1230 >                    catch (InterruptedException ok) {}
1231 >                    return "1"; }};
1232 >            final ExecutorService p = new CustomExecutor(2);
1233 >            try (PoolCleaner cleaner = cleaner(p, done)) {
1234                  List<Callable<String>> tasks = new ArrayList<>();
1235                  tasks.add(new StringTask("0"));
1236 <                tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING));
1236 >                tasks.add(waiter);
1237                  tasks.add(new StringTask("2"));
1238                  long startTime = System.nanoTime();
1239                  List<Future<String>> futures =
1240 <                    e.invokeAll(tasks, timeout, MILLISECONDS);
1240 >                    p.invokeAll(tasks, timeout, MILLISECONDS);
1241                  assertEquals(tasks.size(), futures.size());
1242                  assertTrue(millisElapsedSince(startTime) >= timeout);
1243                  for (Future future : futures)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines