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.21 by dl, Fri May 6 11:22:07 2011 UTC vs.
Revision 1.22 by jsr166, Sat May 7 19:34:51 2011 UTC

# Line 642 | Line 642 | public class ScheduledExecutorSubclassTe
642      public void testPurge() throws InterruptedException {
643          CustomExecutor p = new CustomExecutor(1);
644          ScheduledFuture[] tasks = new ScheduledFuture[5];
645 <        for (int i = 0; i < tasks.length; i++) {
646 <            tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
647 <        }
645 >        for (int i = 0; i < tasks.length; i++)
646 >            tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(),
647 >                                  LONG_DELAY_MS, MILLISECONDS);
648          try {
649              int max = tasks.length;
650              if (tasks[4].cancel(true)) --max;
651              if (tasks[3].cancel(true)) --max;
652              // There must eventually be an interference-free point at
653              // which purge will not fail. (At worst, when queue is empty.)
654 <            int k;
655 <            for (k = 0; k < SMALL_DELAY_MS; ++k) {
654 >            long startTime = System.nanoTime();
655 >            do {
656                  p.purge();
657                  long count = p.getTaskCount();
658 <                if (count >= 0 && count <= max)
659 <                    break;
660 <                delay(1);
661 <            }
662 <            assertTrue(k < SMALL_DELAY_MS);
658 >                if (count == max)
659 >                    return;
660 >            } while (millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
661 >            fail("Purge failed to remove cancelled tasks");
662          } finally {
663              for (ScheduledFuture task : tasks)
664                  task.cancel(true);
# Line 673 | Line 672 | public class ScheduledExecutorSubclassTe
672      public void testShutDownNow() {
673          CustomExecutor p = new CustomExecutor(1);
674          for (int i = 0; i < 5; i++)
675 <            p.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
676 <        List l;
675 >            p.schedule(new SmallPossiblyInterruptedRunnable(),
676 >                       LONG_DELAY_MS, MILLISECONDS);
677          try {
678 <            l = p.shutdownNow();
678 >            List<Runnable> l = p.shutdownNow();
679 >            assertTrue(p.isShutdown());
680 >            assertEquals(5, l.size());
681          } catch (SecurityException ok) {
682 <            return;
682 >            // Allowed in case test doesn't have privs
683 >        } finally {
684 >            joinPool(p);
685          }
683        assertTrue(p.isShutdown());
684        assertTrue(l.size() > 0 && l.size() <= 5);
685        joinPool(p);
686      }
687  
688      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines