123 |
|
final CustomExecutor p = new CustomExecutor(1); |
124 |
|
try (PoolCleaner cleaner = cleaner(p, done)) { |
125 |
|
final long startTime = System.nanoTime(); |
126 |
< |
Callable task = new CheckedCallable<Boolean>() { |
126 |
> |
Callable<Boolean> task = new CheckedCallable<Boolean>() { |
127 |
|
public Boolean realCall() { |
128 |
|
done.countDown(); |
129 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
130 |
|
return Boolean.TRUE; |
131 |
|
}}; |
132 |
< |
Future f = p.schedule(task, timeoutMillis(), MILLISECONDS); |
132 |
> |
Future<Boolean> f = p.schedule(task, timeoutMillis(), MILLISECONDS); |
133 |
|
assertSame(Boolean.TRUE, f.get()); |
134 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
135 |
|
} |
148 |
|
done.countDown(); |
149 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
150 |
|
}}; |
151 |
< |
Future f = p.schedule(task, timeoutMillis(), MILLISECONDS); |
151 |
> |
Future<?> f = p.schedule(task, timeoutMillis(), MILLISECONDS); |
152 |
|
await(done); |
153 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
154 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
168 |
|
done.countDown(); |
169 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
170 |
|
}}; |
171 |
< |
ScheduledFuture f = |
171 |
> |
ScheduledFuture<?> f = |
172 |
|
p.scheduleAtFixedRate(task, timeoutMillis(), |
173 |
|
LONG_DELAY_MS, MILLISECONDS); |
174 |
|
await(done); |
190 |
|
done.countDown(); |
191 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
192 |
|
}}; |
193 |
< |
ScheduledFuture f = |
193 |
> |
ScheduledFuture<?> f = |
194 |
|
p.scheduleWithFixedDelay(task, timeoutMillis(), |
195 |
|
LONG_DELAY_MS, MILLISECONDS); |
196 |
|
await(done); |
218 |
|
final CountDownLatch done = new CountDownLatch(cycles); |
219 |
|
final Runnable task = new CheckedRunnable() { |
220 |
|
public void realRun() { done.countDown(); }}; |
221 |
< |
final ScheduledFuture periodicTask = |
221 |
> |
final ScheduledFuture<?> periodicTask = |
222 |
|
p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS); |
223 |
|
final int totalDelayMillis = (cycles - 1) * delay; |
224 |
|
await(done, totalDelayMillis + LONG_DELAY_MS); |
264 |
|
previous.set(now); |
265 |
|
done.countDown(); |
266 |
|
}}; |
267 |
< |
final ScheduledFuture periodicTask = |
267 |
> |
final ScheduledFuture<?> periodicTask = |
268 |
|
p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS); |
269 |
|
final int totalDelayMillis = (cycles - 1) * delay; |
270 |
|
await(done, totalDelayMillis + cycles * LONG_DELAY_MS); |
591 |
|
final ScheduledThreadPoolExecutor p = new CustomExecutor(1); |
592 |
|
try (PoolCleaner cleaner = cleaner(p, done)) { |
593 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
594 |
< |
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
594 |
> |
@SuppressWarnings("unchecked") |
595 |
> |
ScheduledFuture<?>[] tasks = (ScheduledFuture<?>[])new ScheduledFuture[5]; |
596 |
|
for (int i = 0; i < tasks.length; i++) { |
597 |
|
Runnable r = new CheckedRunnable() { |
598 |
|
public void realRun() throws InterruptedException { |
615 |
|
final CountDownLatch done = new CountDownLatch(1); |
616 |
|
final ScheduledThreadPoolExecutor p = new CustomExecutor(1); |
617 |
|
try (PoolCleaner cleaner = cleaner(p, done)) { |
618 |
< |
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
618 |
> |
@SuppressWarnings("unchecked") |
619 |
> |
ScheduledFuture<?>[] tasks = (ScheduledFuture<?>[])new ScheduledFuture[5]; |
620 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
621 |
|
for (int i = 0; i < tasks.length; i++) { |
622 |
|
Runnable r = new CheckedRunnable() { |
644 |
|
* purge removes cancelled tasks from the queue |
645 |
|
*/ |
646 |
|
public void testPurge() throws InterruptedException { |
647 |
< |
final ScheduledFuture[] tasks = new ScheduledFuture[5]; |
647 |
> |
@SuppressWarnings("unchecked") |
648 |
> |
ScheduledFuture<?>[] tasks = (ScheduledFuture<?>[])new ScheduledFuture[5]; |
649 |
|
final Runnable releaser = new Runnable() { public void run() { |
650 |
< |
for (ScheduledFuture task : tasks) |
650 |
> |
for (ScheduledFuture<?> task : tasks) |
651 |
|
if (task != null) task.cancel(true); }}; |
652 |
|
final CustomExecutor p = new CustomExecutor(1); |
653 |
|
try (PoolCleaner cleaner = cleaner(p, releaser)) { |
713 |
|
*/ |
714 |
|
public void testShutdownNow_delayedTasks() throws InterruptedException { |
715 |
|
final CustomExecutor p = new CustomExecutor(1); |
716 |
< |
List<ScheduledFuture> tasks = new ArrayList<>(); |
716 |
> |
List<ScheduledFuture<?>> tasks = new ArrayList<>(); |
717 |
|
for (int i = 0; i < 3; i++) { |
718 |
|
Runnable r = new NoOpRunnable(); |
719 |
|
tasks.add(p.schedule(r, 9, SECONDS)); |
721 |
|
tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS)); |
722 |
|
} |
723 |
|
if (testImplementationDetails) |
724 |
< |
assertEquals(new HashSet(tasks), new HashSet(p.getQueue())); |
724 |
> |
assertEquals(new HashSet<Object>(tasks), new HashSet<Object>(p.getQueue())); |
725 |
|
final List<Runnable> queuedTasks; |
726 |
|
try { |
727 |
|
queuedTasks = p.shutdownNow(); |
731 |
|
assertTrue(p.isShutdown()); |
732 |
|
assertTrue(p.getQueue().isEmpty()); |
733 |
|
if (testImplementationDetails) |
734 |
< |
assertEquals(new HashSet(tasks), new HashSet(queuedTasks)); |
734 |
> |
assertEquals(new HashSet<Object>(tasks), new HashSet<Object>(queuedTasks)); |
735 |
|
assertEquals(tasks.size(), queuedTasks.size()); |
736 |
< |
for (ScheduledFuture task : tasks) { |
736 |
> |
for (ScheduledFuture<?> task : tasks) { |
737 |
|
assertFalse(((CustomTask)task).ran); |
738 |
|
assertFalse(task.isDone()); |
739 |
|
assertFalse(task.isCancelled()); |
1332 |
|
p.invokeAll(tasks, timeout, MILLISECONDS); |
1333 |
|
assertEquals(tasks.size(), futures.size()); |
1334 |
|
assertTrue(millisElapsedSince(startTime) >= timeout); |
1335 |
< |
for (Future future : futures) |
1335 |
> |
for (Future<?> future : futures) |
1336 |
|
assertTrue(future.isDone()); |
1337 |
|
assertTrue(futures.get(1).isCancelled()); |
1338 |
|
try { |