507 |
|
} |
508 |
|
|
509 |
|
/** |
510 |
+ |
* The default rejected execution handler is AbortPolicy. |
511 |
+ |
*/ |
512 |
+ |
public void testDefaultRejectedExecutionHandler() { |
513 |
+ |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
514 |
+ |
try (PoolCleaner cleaner = cleaner(p)) { |
515 |
+ |
assertTrue(p.getRejectedExecutionHandler() |
516 |
+ |
instanceof ThreadPoolExecutor.AbortPolicy); |
517 |
+ |
} |
518 |
+ |
} |
519 |
+ |
|
520 |
+ |
/** |
521 |
|
* isShutdown is false before shutdown, true after |
522 |
|
*/ |
523 |
|
public void testIsShutdown() { |
513 |
– |
|
524 |
|
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
525 |
< |
try { |
526 |
< |
assertFalse(p.isShutdown()); |
527 |
< |
} |
528 |
< |
finally { |
529 |
< |
try { p.shutdown(); } catch (SecurityException ok) { return; } |
525 |
> |
assertFalse(p.isShutdown()); |
526 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
527 |
> |
try { |
528 |
> |
p.shutdown(); |
529 |
> |
assertTrue(p.isShutdown()); |
530 |
> |
} catch (SecurityException ok) {} |
531 |
|
} |
521 |
– |
assertTrue(p.isShutdown()); |
532 |
|
} |
533 |
|
|
534 |
|
/** |
825 |
|
assertTrue(periodic.isDone()); |
826 |
|
} |
827 |
|
} |
828 |
+ |
for (Future<?> blocker : blockers) assertNull(blocker.get()); |
829 |
|
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
830 |
|
assertTrue(p.isTerminated()); |
831 |
|
assertEquals(2 + (effectiveDelayedPolicy ? 1 : 0), ran.get()); |
900 |
|
CountDownLatch latch = new CountDownLatch(1); |
901 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
902 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
903 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
903 |
> |
List<Callable<String>> l = new ArrayList<>(); |
904 |
|
l.add(latchAwaitingStringTask(latch)); |
905 |
|
l.add(null); |
906 |
|
try { |
917 |
|
public void testInvokeAny4() throws Exception { |
918 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
919 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
920 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
920 |
> |
List<Callable<String>> l = new ArrayList<>(); |
921 |
|
l.add(new NPETask()); |
922 |
|
try { |
923 |
|
e.invokeAny(l); |
934 |
|
public void testInvokeAny5() throws Exception { |
935 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
936 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
937 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
937 |
> |
List<Callable<String>> l = new ArrayList<>(); |
938 |
|
l.add(new StringTask()); |
939 |
|
l.add(new StringTask()); |
940 |
|
String result = e.invokeAny(l); |
972 |
|
public void testInvokeAll3() throws Exception { |
973 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
974 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
975 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
975 |
> |
List<Callable<String>> l = new ArrayList<>(); |
976 |
|
l.add(new StringTask()); |
977 |
|
l.add(null); |
978 |
|
try { |
988 |
|
public void testInvokeAll4() throws Exception { |
989 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
990 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
991 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
991 |
> |
List<Callable<String>> l = new ArrayList<>(); |
992 |
|
l.add(new NPETask()); |
993 |
|
List<Future<String>> futures = e.invokeAll(l); |
994 |
|
assertEquals(1, futures.size()); |
1007 |
|
public void testInvokeAll5() throws Exception { |
1008 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1009 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1010 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1010 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1011 |
|
l.add(new StringTask()); |
1012 |
|
l.add(new StringTask()); |
1013 |
|
List<Future<String>> futures = e.invokeAll(l); |
1036 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
1037 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1038 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1039 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1039 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1040 |
|
l.add(new StringTask()); |
1041 |
|
try { |
1042 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1065 |
|
CountDownLatch latch = new CountDownLatch(1); |
1066 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1067 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1068 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1068 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1069 |
|
l.add(latchAwaitingStringTask(latch)); |
1070 |
|
l.add(null); |
1071 |
|
try { |
1083 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1084 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1085 |
|
long startTime = System.nanoTime(); |
1086 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1086 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1087 |
|
l.add(new NPETask()); |
1088 |
|
try { |
1089 |
|
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1102 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1103 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1104 |
|
long startTime = System.nanoTime(); |
1105 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1105 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1106 |
|
l.add(new StringTask()); |
1107 |
|
l.add(new StringTask()); |
1108 |
|
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1130 |
|
public void testTimedInvokeAllNullTimeUnit() throws Exception { |
1131 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1132 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1133 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1133 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1134 |
|
l.add(new StringTask()); |
1135 |
|
try { |
1136 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1157 |
|
public void testTimedInvokeAll3() throws Exception { |
1158 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1159 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1160 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1160 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1161 |
|
l.add(new StringTask()); |
1162 |
|
l.add(null); |
1163 |
|
try { |
1173 |
|
public void testTimedInvokeAll4() throws Exception { |
1174 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1175 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1176 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1176 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1177 |
|
l.add(new NPETask()); |
1178 |
|
List<Future<String>> futures = |
1179 |
|
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); |
1193 |
|
public void testTimedInvokeAll5() throws Exception { |
1194 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1195 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1196 |
< |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1196 |
> |
List<Callable<String>> l = new ArrayList<>(); |
1197 |
|
l.add(new StringTask()); |
1198 |
|
l.add(new StringTask()); |
1199 |
|
List<Future<String>> futures = |