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.46 by jsr166, Tue May 31 16:16:24 2011 UTC vs.
Revision 1.49 by jsr166, Wed Sep 25 07:39:17 2013 UTC

# Line 141 | Line 141 | public class ScheduledExecutorTest exten
141       */
142      public void testFixedRateSequence() throws InterruptedException {
143          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
144 <        RunnableCounter counter = new RunnableCounter();
145 <        ScheduledFuture h =
146 <            p.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
147 <        delay(SMALL_DELAY_MS);
148 <        h.cancel(true);
149 <        int c = counter.count.get();
150 <        // By time scaling conventions, we must have at least
151 <        // an execution per SHORT delay, but no more than one SHORT more
152 <        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
153 <        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
154 <        joinPool(p);
144 >        try {
145 >            for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
146 >                long startTime = System.nanoTime();
147 >                int cycles = 10;
148 >                final CountDownLatch done = new CountDownLatch(cycles);
149 >                Runnable task = new CheckedRunnable() {
150 >                    public void realRun() { done.countDown(); }};
151 >                ScheduledFuture h =
152 >                    p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
153 >                done.await();
154 >                h.cancel(true);
155 >                double normalizedTime =
156 >                    (double) millisElapsedSince(startTime) / delay;
157 >                if (normalizedTime >= cycles - 1 &&
158 >                    normalizedTime <= cycles)
159 >                    return;
160 >            }
161 >            throw new AssertionError("unexpected execution rate");
162 >        } finally {
163 >            joinPool(p);
164 >        }
165      }
166  
167      /**
# Line 159 | Line 169 | public class ScheduledExecutorTest exten
169       */
170      public void testFixedDelaySequence() throws InterruptedException {
171          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
172 <        RunnableCounter counter = new RunnableCounter();
173 <        ScheduledFuture h =
174 <            p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
175 <        delay(SMALL_DELAY_MS);
176 <        h.cancel(true);
177 <        int c = counter.count.get();
178 <        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
179 <        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
180 <        joinPool(p);
172 >        try {
173 >            for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
174 >                long startTime = System.nanoTime();
175 >                int cycles = 10;
176 >                final CountDownLatch done = new CountDownLatch(cycles);
177 >                Runnable task = new CheckedRunnable() {
178 >                    public void realRun() { done.countDown(); }};
179 >                ScheduledFuture h =
180 >                    p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
181 >                done.await();
182 >                h.cancel(true);
183 >                double normalizedTime =
184 >                    (double) millisElapsedSince(startTime) / delay;
185 >                if (normalizedTime >= cycles - 1 &&
186 >                    normalizedTime <= cycles)
187 >                    return;
188 >            }
189 >            throw new AssertionError("unexpected execution rate");
190 >        } finally {
191 >            joinPool(p);
192 >        }
193      }
194  
195      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines