9 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
10 |
|
|
11 |
|
import java.util.ArrayList; |
12 |
+ |
import java.util.Collection; |
13 |
+ |
import java.util.Collections; |
14 |
|
import java.util.HashSet; |
15 |
|
import java.util.List; |
16 |
|
import java.util.concurrent.BlockingQueue; |
299 |
|
final CustomExecutor p = new CustomExecutor(1); |
300 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
301 |
|
try { |
302 |
< |
TrackedCallable callable = null; |
303 |
< |
Future f = p.schedule(callable, SHORT_DELAY_MS, MILLISECONDS); |
302 |
> |
Future f = p.schedule((Callable)null, |
303 |
> |
randomTimeout(), randomTimeUnit()); |
304 |
|
shouldThrow(); |
305 |
|
} catch (NullPointerException success) {} |
306 |
|
} |
315 |
|
try { |
316 |
|
p.shutdown(); |
317 |
|
p.schedule(new NoOpRunnable(), |
318 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
318 |
> |
randomTimeout(), randomTimeUnit()); |
319 |
|
shouldThrow(); |
320 |
|
} catch (RejectedExecutionException success) { |
321 |
|
} catch (SecurityException ok) {} |
331 |
|
try { |
332 |
|
p.shutdown(); |
333 |
|
p.schedule(new NoOpCallable(), |
334 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
334 |
> |
randomTimeout(), randomTimeUnit()); |
335 |
|
shouldThrow(); |
336 |
|
} catch (RejectedExecutionException success) { |
337 |
|
} catch (SecurityException ok) {} |
347 |
|
try { |
348 |
|
p.shutdown(); |
349 |
|
p.schedule(new NoOpCallable(), |
350 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
350 |
> |
randomTimeout(), randomTimeUnit()); |
351 |
|
shouldThrow(); |
352 |
|
} catch (RejectedExecutionException success) { |
353 |
|
} catch (SecurityException ok) {} |
1020 |
|
} |
1021 |
|
|
1022 |
|
/** |
1023 |
< |
* invokeAny(empty collection) throws IAE |
1023 |
> |
* invokeAny(empty collection) throws IllegalArgumentException |
1024 |
|
*/ |
1025 |
|
public void testInvokeAny2() throws Exception { |
1026 |
|
final ExecutorService e = new CustomExecutor(2); |
1095 |
|
} |
1096 |
|
|
1097 |
|
/** |
1098 |
< |
* invokeAll(empty collection) returns empty collection |
1098 |
> |
* invokeAll(empty collection) returns empty list |
1099 |
|
*/ |
1100 |
|
public void testInvokeAll2() throws Exception { |
1101 |
|
final ExecutorService e = new CustomExecutor(2); |
1102 |
+ |
final Collection<Callable<String>> emptyCollection |
1103 |
+ |
= Collections.emptyList(); |
1104 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1105 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
1105 |
> |
List<Future<String>> r = e.invokeAll(emptyCollection); |
1106 |
|
assertTrue(r.isEmpty()); |
1107 |
|
} |
1108 |
|
} |
1165 |
|
final ExecutorService e = new CustomExecutor(2); |
1166 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1167 |
|
try { |
1168 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
1168 |
> |
e.invokeAny(null, randomTimeout(), randomTimeUnit()); |
1169 |
|
shouldThrow(); |
1170 |
|
} catch (NullPointerException success) {} |
1171 |
|
} |
1180 |
|
List<Callable<String>> l = new ArrayList<>(); |
1181 |
|
l.add(new StringTask()); |
1182 |
|
try { |
1183 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1183 |
> |
e.invokeAny(l, randomTimeout(), null); |
1184 |
|
shouldThrow(); |
1185 |
|
} catch (NullPointerException success) {} |
1186 |
|
} |
1187 |
|
} |
1188 |
|
|
1189 |
|
/** |
1190 |
< |
* timed invokeAny(empty collection) throws IAE |
1190 |
> |
* timed invokeAny(empty collection) throws IllegalArgumentException |
1191 |
|
*/ |
1192 |
|
public void testTimedInvokeAny2() throws Exception { |
1193 |
|
final ExecutorService e = new CustomExecutor(2); |
1194 |
+ |
final Collection<Callable<String>> emptyCollection |
1195 |
+ |
= Collections.emptyList(); |
1196 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1197 |
|
try { |
1198 |
< |
e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
1198 |
> |
e.invokeAny(emptyCollection, randomTimeout(), randomTimeUnit()); |
1199 |
|
shouldThrow(); |
1200 |
|
} catch (IllegalArgumentException success) {} |
1201 |
|
} |
1212 |
|
l.add(latchAwaitingStringTask(latch)); |
1213 |
|
l.add(null); |
1214 |
|
try { |
1215 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1215 |
> |
e.invokeAny(l, randomTimeout(), randomTimeUnit()); |
1216 |
|
shouldThrow(); |
1217 |
|
} catch (NullPointerException success) {} |
1218 |
|
latch.countDown(); |
1255 |
|
} |
1256 |
|
|
1257 |
|
/** |
1258 |
< |
* timed invokeAll(null) throws NPE |
1258 |
> |
* timed invokeAll(null) throws NullPointerException |
1259 |
|
*/ |
1260 |
|
public void testTimedInvokeAll1() throws Exception { |
1261 |
|
final ExecutorService e = new CustomExecutor(2); |
1262 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1263 |
|
try { |
1264 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
1264 |
> |
e.invokeAll(null, randomTimeout(), randomTimeUnit()); |
1265 |
|
shouldThrow(); |
1266 |
|
} catch (NullPointerException success) {} |
1267 |
|
} |
1268 |
|
} |
1269 |
|
|
1270 |
|
/** |
1271 |
< |
* timed invokeAll(,,null) throws NPE |
1271 |
> |
* timed invokeAll(,,null) throws NullPointerException |
1272 |
|
*/ |
1273 |
|
public void testTimedInvokeAllNullTimeUnit() throws Exception { |
1274 |
|
final ExecutorService e = new CustomExecutor(2); |
1276 |
|
List<Callable<String>> l = new ArrayList<>(); |
1277 |
|
l.add(new StringTask()); |
1278 |
|
try { |
1279 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1279 |
> |
e.invokeAll(l, randomTimeout(), null); |
1280 |
|
shouldThrow(); |
1281 |
|
} catch (NullPointerException success) {} |
1282 |
|
} |
1283 |
|
} |
1284 |
|
|
1285 |
|
/** |
1286 |
< |
* timed invokeAll(empty collection) returns empty collection |
1286 |
> |
* timed invokeAll(empty collection) returns empty list |
1287 |
|
*/ |
1288 |
|
public void testTimedInvokeAll2() throws Exception { |
1289 |
|
final ExecutorService e = new CustomExecutor(2); |
1290 |
+ |
final Collection<Callable<String>> emptyCollection |
1291 |
+ |
= Collections.emptyList(); |
1292 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1293 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); |
1293 |
> |
List<Future<String>> r = |
1294 |
> |
e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit()); |
1295 |
|
assertTrue(r.isEmpty()); |
1296 |
|
} |
1297 |
|
} |
1306 |
|
l.add(new StringTask()); |
1307 |
|
l.add(null); |
1308 |
|
try { |
1309 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1309 |
> |
e.invokeAll(l, randomTimeout(), randomTimeUnit()); |
1310 |
|
shouldThrow(); |
1311 |
|
} catch (NullPointerException success) {} |
1312 |
|
} |
1317 |
|
*/ |
1318 |
|
public void testTimedInvokeAll4() throws Exception { |
1319 |
|
final ExecutorService e = new CustomExecutor(2); |
1320 |
+ |
final Collection<Callable<String>> c = new ArrayList<>(); |
1321 |
+ |
c.add(new NPETask()); |
1322 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1312 |
– |
List<Callable<String>> l = new ArrayList<>(); |
1313 |
– |
l.add(new NPETask()); |
1323 |
|
List<Future<String>> futures = |
1324 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1324 |
> |
e.invokeAll(c, LONG_DELAY_MS, MILLISECONDS); |
1325 |
|
assertEquals(1, futures.size()); |
1326 |
|
try { |
1327 |
|
futures.get(0).get(); |