117 |
|
unexpectedException(); |
118 |
|
} |
119 |
|
assertEquals(1, p2.getCompletedTaskCount()); |
120 |
< |
p2.shutdown(); |
120 |
> |
try { p2.shutdown(); } catch(SecurityException ok) { return; } |
121 |
|
joinPool(p2); |
122 |
|
} |
123 |
|
|
147 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
148 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler()); |
149 |
|
assertSame(tf, p.getThreadFactory()); |
150 |
– |
p.shutdown(); |
150 |
|
joinPool(p); |
151 |
|
} |
152 |
|
|
158 |
|
ThreadFactory tf = new SimpleThreadFactory(); |
159 |
|
p.setThreadFactory(tf); |
160 |
|
assertSame(tf, p.getThreadFactory()); |
162 |
– |
p.shutdown(); |
161 |
|
joinPool(p); |
162 |
|
} |
163 |
|
|
183 |
|
RejectedExecutionHandler h = new NoOpREHandler(); |
184 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), h); |
185 |
|
assertSame(h, p.getRejectedExecutionHandler()); |
188 |
– |
p.shutdown(); |
186 |
|
joinPool(p); |
187 |
|
} |
188 |
|
|
195 |
|
RejectedExecutionHandler h = new NoOpREHandler(); |
196 |
|
p.setRejectedExecutionHandler(h); |
197 |
|
assertSame(h, p.getRejectedExecutionHandler()); |
201 |
– |
p.shutdown(); |
198 |
|
joinPool(p); |
199 |
|
} |
200 |
|
|
277 |
|
|
278 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
279 |
|
assertFalse(p1.isShutdown()); |
280 |
< |
p1.shutdown(); |
280 |
> |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
281 |
|
assertTrue(p1.isShutdown()); |
282 |
|
joinPool(p1); |
283 |
|
} |
292 |
|
try { |
293 |
|
p1.execute(new MediumRunnable()); |
294 |
|
} finally { |
295 |
< |
p1.shutdown(); |
295 |
> |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
296 |
|
} |
297 |
|
try { |
298 |
|
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
312 |
|
p1.execute(new SmallRunnable()); |
313 |
|
assertFalse(p1.isTerminating()); |
314 |
|
} finally { |
315 |
< |
p1.shutdown(); |
315 |
> |
try { p1.shutdown(); } catch(SecurityException ok) { return; } |
316 |
|
} |
317 |
|
try { |
318 |
|
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
340 |
|
assertSame(q, wq); |
341 |
|
assertFalse(wq.contains(tasks[0])); |
342 |
|
assertTrue(wq.contains(tasks[4])); |
347 |
– |
p1.shutdownNow(); |
343 |
|
} catch(Exception e) { |
344 |
|
unexpectedException(); |
345 |
|
} finally { |
369 |
|
assertTrue(q.contains(tasks[3])); |
370 |
|
assertTrue(p1.remove(tasks[3])); |
371 |
|
assertFalse(q.contains(tasks[3])); |
377 |
– |
p1.shutdownNow(); |
372 |
|
} catch(Exception e) { |
373 |
|
unexpectedException(); |
374 |
|
} finally { |
391 |
|
p1.purge(); |
392 |
|
long count = p1.getTaskCount(); |
393 |
|
assertTrue(count >= 2 && count < 5); |
400 |
– |
p1.shutdownNow(); |
394 |
|
joinPool(p1); |
395 |
|
} |
396 |
|
|
405 |
|
p1.execute(new MediumPossiblyInterruptedRunnable()); |
406 |
|
} |
407 |
|
finally { |
408 |
< |
l = p1.shutdownNow(); |
408 |
> |
try { |
409 |
> |
l = p1.shutdownNow(); |
410 |
> |
} catch (SecurityException ok) { return; } |
411 |
> |
|
412 |
|
} |
413 |
|
assertTrue(p1.isShutdown()); |
414 |
|
assertTrue(l.size() <= 4); |
769 |
|
for(int i = 1; i < 5; ++i) { |
770 |
|
assertTrue(tasks[i].done); |
771 |
|
} |
772 |
< |
p.shutdownNow(); |
772 |
> |
try { p.shutdownNow(); } catch(SecurityException ok) { return; } |
773 |
|
} catch(RejectedExecutionException ex){ |
774 |
|
unexpectedException(); |
775 |
|
} finally { |
796 |
|
for(int i = 0; i < 5; ++i){ |
797 |
|
assertFalse(tasks[i].done); |
798 |
|
} |
799 |
< |
p.shutdownNow(); |
799 |
> |
try { p.shutdownNow(); } catch(SecurityException ok) { return; } |
800 |
|
} catch(RejectedExecutionException ex){ |
801 |
|
unexpectedException(); |
802 |
|
} finally { |
819 |
|
p.execute(r3); |
820 |
|
assertFalse(p.getQueue().contains(r2)); |
821 |
|
assertTrue(p.getQueue().contains(r3)); |
822 |
< |
p.shutdownNow(); |
822 |
> |
try { p.shutdownNow(); } catch(SecurityException ok) { return; } |
823 |
|
} catch(RejectedExecutionException ex){ |
824 |
|
unexpectedException(); |
825 |
|
} finally { |
833 |
|
public void testRejectedExecutionExceptionOnShutdown() { |
834 |
|
ThreadPoolExecutor tpe = |
835 |
|
new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
836 |
< |
tpe.shutdown(); |
836 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
837 |
|
try { |
838 |
|
tpe.execute(new NoOpRunnable()); |
839 |
|
shouldThrow(); |
849 |
|
RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy(); |
850 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
851 |
|
|
852 |
< |
p.shutdown(); |
852 |
> |
try { p.shutdown(); } catch(SecurityException ok) { return; } |
853 |
|
try { |
854 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
855 |
|
p.execute(r); |
868 |
|
RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy(); |
869 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
870 |
|
|
871 |
< |
p.shutdown(); |
871 |
> |
try { p.shutdown(); } catch(SecurityException ok) { return; } |
872 |
|
try { |
873 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
874 |
|
p.execute(r); |
888 |
|
RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy(); |
889 |
|
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); |
890 |
|
|
891 |
< |
p.shutdown(); |
891 |
> |
try { p.shutdown(); } catch(SecurityException ok) { return; } |
892 |
|
try { |
893 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
894 |
|
p.execute(r); |
928 |
|
shouldThrow(); |
929 |
|
} catch(IllegalArgumentException success){ |
930 |
|
} finally { |
931 |
< |
tpe.shutdown(); |
931 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
932 |
|
} |
933 |
|
joinPool(tpe); |
934 |
|
} |
947 |
|
shouldThrow(); |
948 |
|
} catch(IllegalArgumentException success){ |
949 |
|
} finally { |
950 |
< |
tpe.shutdown(); |
950 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
951 |
|
} |
952 |
|
joinPool(tpe); |
953 |
|
} |
966 |
|
shouldThrow(); |
967 |
|
} catch(IllegalArgumentException success){ |
968 |
|
} finally { |
969 |
< |
tpe.shutdown(); |
969 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
970 |
|
} |
971 |
|
joinPool(tpe); |
972 |
|
} |
987 |
|
shouldThrow(); |
988 |
|
} catch(IllegalArgumentException success){ |
989 |
|
} finally { |
990 |
< |
tpe.shutdown(); |
990 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
991 |
|
} |
992 |
|
joinPool(tpe); |
993 |
|
} |
997 |
|
*/ |
998 |
|
public void testTerminated() { |
999 |
|
ExtendedTPE tpe = new ExtendedTPE(); |
1000 |
< |
tpe.shutdown(); |
1000 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
1001 |
|
assertTrue(tpe.terminatedCalled); |
1002 |
|
joinPool(tpe); |
1003 |
|
} |
1014 |
|
assertTrue(r.done); |
1015 |
|
assertTrue(tpe.beforeCalled); |
1016 |
|
assertTrue(tpe.afterCalled); |
1017 |
< |
tpe.shutdown(); |
1017 |
> |
try { tpe.shutdown(); } catch(SecurityException ok) { return; } |
1018 |
|
} |
1019 |
|
catch(Exception ex) { |
1020 |
|
unexpectedException(); |
1479 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1480 |
|
l.add(new StringTask()); |
1481 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
1482 |
+ |
l.add(new StringTask()); |
1483 |
|
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
1484 |
< |
assertEquals(2, result.size()); |
1484 |
> |
assertEquals(3, result.size()); |
1485 |
|
Iterator<Future<String>> it = result.iterator(); |
1486 |
|
Future<String> f1 = it.next(); |
1487 |
|
Future<String> f2 = it.next(); |
1488 |
+ |
Future<String> f3 = it.next(); |
1489 |
|
assertTrue(f1.isDone()); |
1492 |
– |
assertFalse(f1.isCancelled()); |
1490 |
|
assertTrue(f2.isDone()); |
1491 |
+ |
assertTrue(f3.isDone()); |
1492 |
+ |
assertFalse(f1.isCancelled()); |
1493 |
|
assertTrue(f2.isCancelled()); |
1494 |
|
} catch(Exception ex) { |
1495 |
|
unexpectedException(); |