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.47 by jsr166, Tue Sep 24 18:35:21 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 >                CheckedRunnable task = new CheckedRunnable() {
150 >                    public void realRun() { done.countDown(); }};
151 >                
152 >                ScheduledFuture h =
153 >                    p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
154 >                done.await();
155 >                h.cancel(true);
156 >                double normalizedTime =
157 >                    (double) millisElapsedSince(startTime) / delay;
158 >                if (normalizedTime >= cycles - 1 &&
159 >                    normalizedTime <= cycles)
160 >                    return;
161 >            }
162 >            throw new AssertionError("unexpected execution rate");
163 >        } finally {
164 >            joinPool(p);
165 >        }
166      }
167  
168      /**
# Line 159 | Line 170 | public class ScheduledExecutorTest exten
170       */
171      public void testFixedDelaySequence() throws InterruptedException {
172          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
173 <        RunnableCounter counter = new RunnableCounter();
174 <        ScheduledFuture h =
175 <            p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
176 <        delay(SMALL_DELAY_MS);
177 <        h.cancel(true);
178 <        int c = counter.count.get();
179 <        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
180 <        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
181 <        joinPool(p);
173 >        try {
174 >            for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
175 >                long startTime = System.nanoTime();
176 >                int cycles = 10;
177 >                final CountDownLatch done = new CountDownLatch(cycles);
178 >                CheckedRunnable task = new CheckedRunnable() {
179 >                    public void realRun() { done.countDown(); }};
180 >                
181 >                ScheduledFuture h =
182 >                    p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
183 >                done.await();
184 >                h.cancel(true);
185 >                double normalizedTime =
186 >                    (double) millisElapsedSince(startTime) / delay;
187 >                if (normalizedTime >= cycles - 1 &&
188 >                    normalizedTime <= cycles)
189 >                    return;
190 >            }
191 >            throw new AssertionError("unexpected execution rate");
192 >        } finally {
193 >            joinPool(p);
194 >        }
195      }
196  
197      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines