17 |
|
return new TestSuite(ThreadPoolExecutorTest.class); |
18 |
|
} |
19 |
|
|
20 |
– |
/** |
21 |
– |
* For use as ThreadFactory in constructors |
22 |
– |
*/ |
23 |
– |
static class MyThreadFactory implements ThreadFactory{ |
24 |
– |
public Thread newThread(Runnable r){ |
25 |
– |
return new Thread(r); |
26 |
– |
} |
27 |
– |
} |
20 |
|
|
21 |
|
/** |
30 |
– |
* For use as RejectedExecutionHandler in constructors |
31 |
– |
*/ |
32 |
– |
static class MyREHandler implements RejectedExecutionHandler{ |
33 |
– |
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){} |
34 |
– |
} |
35 |
– |
|
36 |
– |
/** |
22 |
|
* execute successfully executes a runnable |
23 |
|
*/ |
24 |
|
public void testExecute() { |
41 |
|
} |
42 |
|
|
43 |
|
/** |
44 |
< |
* getActiveCount gives correct values |
44 |
> |
* getActiveCount increases but doesn't overestimate, when a |
45 |
> |
* thread becomes active |
46 |
|
*/ |
47 |
|
public void testGetActiveCount() { |
48 |
|
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
58 |
|
} |
59 |
|
|
60 |
|
/** |
61 |
< |
* getCompleteTaskCount gives correct values |
61 |
> |
* getCompletedTaskCount increases, but doesn't overestimate, |
62 |
> |
* when tasks complete |
63 |
|
*/ |
64 |
|
public void testGetCompletedTaskCount() { |
65 |
|
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
76 |
|
} |
77 |
|
|
78 |
|
/** |
79 |
< |
* getCorePoolSize gives correct values |
79 |
> |
* getCorePoolSize returns size given in constructor if not otherwise set |
80 |
|
*/ |
81 |
|
public void testGetCorePoolSize() { |
82 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
85 |
|
} |
86 |
|
|
87 |
|
/** |
88 |
< |
* getKeepAliveTime gives correct values |
88 |
> |
* getKeepAliveTime returns value given in constructor if not otherwise set |
89 |
|
*/ |
90 |
|
public void testGetKeepAliveTime() { |
91 |
|
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
94 |
|
} |
95 |
|
|
96 |
|
/** |
97 |
< |
* getLargestPoolSize gives correct values |
97 |
> |
* getLargestPoolSize increases, but doesn't overestimate, when |
98 |
> |
* multiple threads active |
99 |
|
*/ |
100 |
|
public void testGetLargestPoolSize() { |
101 |
|
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
112 |
|
} |
113 |
|
|
114 |
|
/** |
115 |
< |
* getMaximumPoolSize gives correct values |
115 |
> |
* getMaximumPoolSize returns value given in constructor if not |
116 |
> |
* otherwise set |
117 |
|
*/ |
118 |
|
public void testGetMaximumPoolSize() { |
119 |
|
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
122 |
|
} |
123 |
|
|
124 |
|
/** |
125 |
< |
* getPoolSize gives correct values |
125 |
> |
* getPoolSize increases, but doesn't overestimate, when threads |
126 |
> |
* become active |
127 |
|
*/ |
128 |
|
public void testGetPoolSize() { |
129 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
134 |
|
} |
135 |
|
|
136 |
|
/** |
137 |
< |
* getTaskCount gives correct values |
137 |
> |
* getTaskCount increases, but doesn't overestimate, when tasks submitted |
138 |
|
*/ |
139 |
|
public void testGetTaskCount() { |
140 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
150 |
|
} |
151 |
|
|
152 |
|
/** |
153 |
< |
* isShutDown gives correct values |
153 |
> |
* isShutDown is false before shutdown, true after |
154 |
|
*/ |
155 |
|
public void testIsShutdown() { |
156 |
|
|
163 |
|
|
164 |
|
|
165 |
|
/** |
166 |
< |
* isTerminated gives correct values |
177 |
< |
* Makes sure termination does not take an innapropriate |
178 |
< |
* amount of time |
166 |
> |
* isTerminated is false before termination, true after |
167 |
|
*/ |
168 |
|
public void testIsTerminated() { |
169 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
170 |
+ |
assertFalse(p1.isTerminated()); |
171 |
|
try { |
172 |
|
p1.execute(new MediumRunnable()); |
173 |
|
} finally { |
182 |
|
} |
183 |
|
|
184 |
|
/** |
185 |
< |
* isTerminating gives correct values |
185 |
> |
* isTerminating is not true when running or when terminated |
186 |
|
*/ |
187 |
|
public void testIsTerminating() { |
188 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
203 |
|
} |
204 |
|
|
205 |
|
/** |
206 |
< |
* purge correctly removes cancelled tasks |
218 |
< |
* from the queue |
206 |
> |
* purge removes cancelled tasks from the queue |
207 |
|
*/ |
208 |
|
public void testPurge() { |
209 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
221 |
|
} |
222 |
|
|
223 |
|
/** |
224 |
< |
* shutDownNow returns a list |
237 |
< |
* containing the correct number of elements |
224 |
> |
* shutDownNow returns a list containing tasks that were not run |
225 |
|
*/ |
226 |
|
public void testShutDownNow() { |
227 |
|
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
240 |
|
// Exception Tests |
241 |
|
|
242 |
|
|
243 |
< |
/** Throws if corePoolSize argument is less than zero */ |
243 |
> |
/** |
244 |
> |
* Constructor throws if corePoolSize argument is less than zero |
245 |
> |
*/ |
246 |
|
public void testConstructor1() { |
247 |
|
try { |
248 |
|
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
251 |
|
catch (IllegalArgumentException success){} |
252 |
|
} |
253 |
|
|
254 |
< |
/** Throws if maximumPoolSize is less than zero */ |
254 |
> |
/** |
255 |
> |
* Constructor throws if maximumPoolSize is less than zero |
256 |
> |
*/ |
257 |
|
public void testConstructor2() { |
258 |
|
try { |
259 |
|
new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
262 |
|
catch (IllegalArgumentException success){} |
263 |
|
} |
264 |
|
|
265 |
< |
/** Throws if maximumPoolSize is equal to zero */ |
265 |
> |
/** |
266 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
267 |
> |
*/ |
268 |
|
public void testConstructor3() { |
269 |
|
try { |
270 |
|
new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
273 |
|
catch (IllegalArgumentException success){} |
274 |
|
} |
275 |
|
|
276 |
< |
/** Throws if keepAliveTime is less than zero */ |
276 |
> |
/** |
277 |
> |
* Constructor throws if keepAliveTime is less than zero |
278 |
> |
*/ |
279 |
|
public void testConstructor4() { |
280 |
|
try { |
281 |
|
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
284 |
|
catch (IllegalArgumentException success){} |
285 |
|
} |
286 |
|
|
287 |
< |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
287 |
> |
/** |
288 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
289 |
> |
*/ |
290 |
|
public void testConstructor5() { |
291 |
|
try { |
292 |
|
new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
295 |
|
catch (IllegalArgumentException success){} |
296 |
|
} |
297 |
|
|
298 |
< |
/** Throws if workQueue is set to null */ |
298 |
> |
/** |
299 |
> |
* Constructor throws if workQueue is set to null |
300 |
> |
*/ |
301 |
|
public void testNullPointerException() { |
302 |
|
try { |
303 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null); |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
< |
/** Throws if corePoolSize argument is less than zero */ |
311 |
> |
/** |
312 |
> |
* Constructor throws if corePoolSize argument is less than zero |
313 |
> |
*/ |
314 |
|
public void testConstructor6() { |
315 |
|
try { |
316 |
< |
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
316 |
> |
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
317 |
|
shouldThrow(); |
318 |
|
} catch (IllegalArgumentException success){} |
319 |
|
} |
320 |
|
|
321 |
< |
/** Throws if maximumPoolSize is less than zero */ |
321 |
> |
/** |
322 |
> |
* Constructor throws if maximumPoolSize is less than zero |
323 |
> |
*/ |
324 |
|
public void testConstructor7() { |
325 |
|
try { |
326 |
< |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
326 |
> |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
327 |
|
shouldThrow(); |
328 |
|
} |
329 |
|
catch (IllegalArgumentException success){} |
330 |
|
} |
331 |
|
|
332 |
< |
/** Throws if maximumPoolSize is equal to zero */ |
332 |
> |
/** |
333 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
334 |
> |
*/ |
335 |
|
public void testConstructor8() { |
336 |
|
try { |
337 |
< |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
337 |
> |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
338 |
|
shouldThrow(); |
339 |
|
} |
340 |
|
catch (IllegalArgumentException success){} |
341 |
|
} |
342 |
|
|
343 |
< |
/** Throws if keepAliveTime is less than zero */ |
343 |
> |
/** |
344 |
> |
* Constructor throws if keepAliveTime is less than zero |
345 |
> |
*/ |
346 |
|
public void testConstructor9() { |
347 |
|
try { |
348 |
< |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
348 |
> |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
349 |
|
shouldThrow(); |
350 |
|
} |
351 |
|
catch (IllegalArgumentException success){} |
352 |
|
} |
353 |
|
|
354 |
< |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
354 |
> |
/** |
355 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
356 |
> |
*/ |
357 |
|
public void testConstructor10() { |
358 |
|
try { |
359 |
< |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
359 |
> |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
360 |
|
shouldThrow(); |
361 |
|
} |
362 |
|
catch (IllegalArgumentException success){} |
363 |
|
} |
364 |
|
|
365 |
< |
/** Throws if workQueue is set to null */ |
365 |
> |
/** |
366 |
> |
* Constructor throws if workQueue is set to null |
367 |
> |
*/ |
368 |
|
public void testNullPointerException2() { |
369 |
|
try { |
370 |
< |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory()); |
370 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory()); |
371 |
|
shouldThrow(); |
372 |
|
} |
373 |
|
catch (NullPointerException success){} |
374 |
|
} |
375 |
|
|
376 |
< |
/** Throws if threadFactory is set to null */ |
376 |
> |
/** |
377 |
> |
* Constructor throws if threadFactory is set to null |
378 |
> |
*/ |
379 |
|
public void testNullPointerException3() { |
380 |
|
try { |
381 |
|
ThreadFactory f = null; |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
< |
/** Throws if corePoolSize argument is less than zero */ |
389 |
> |
/** |
390 |
> |
* Constructor throws if corePoolSize argument is less than zero |
391 |
> |
*/ |
392 |
|
public void testConstructor11() { |
393 |
|
try { |
394 |
< |
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
394 |
> |
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
395 |
|
shouldThrow(); |
396 |
|
} |
397 |
|
catch (IllegalArgumentException success){} |
398 |
|
} |
399 |
|
|
400 |
< |
/** Throws if maximumPoolSize is less than zero */ |
400 |
> |
/** |
401 |
> |
* Constructor throws if maximumPoolSize is less than zero |
402 |
> |
*/ |
403 |
|
public void testConstructor12() { |
404 |
|
try { |
405 |
< |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
405 |
> |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
406 |
|
shouldThrow(); |
407 |
|
} |
408 |
|
catch (IllegalArgumentException success){} |
409 |
|
} |
410 |
|
|
411 |
< |
/** Throws if maximumPoolSize is equal to zero */ |
411 |
> |
/** |
412 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
413 |
> |
*/ |
414 |
|
public void testConstructor13() { |
415 |
|
try { |
416 |
< |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
416 |
> |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
417 |
|
shouldThrow(); |
418 |
|
} |
419 |
|
catch (IllegalArgumentException success){} |
420 |
|
} |
421 |
|
|
422 |
< |
/** Throws if keepAliveTime is less than zero */ |
422 |
> |
/** |
423 |
> |
* Constructor throws if keepAliveTime is less than zero |
424 |
> |
*/ |
425 |
|
public void testConstructor14() { |
426 |
|
try { |
427 |
< |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
427 |
> |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
428 |
|
shouldThrow(); |
429 |
|
} |
430 |
|
catch (IllegalArgumentException success){} |
431 |
|
} |
432 |
|
|
433 |
< |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
433 |
> |
/** |
434 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
435 |
> |
*/ |
436 |
|
public void testConstructor15() { |
437 |
|
try { |
438 |
< |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
438 |
> |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
439 |
|
shouldThrow(); |
440 |
|
} |
441 |
|
catch (IllegalArgumentException success){} |
442 |
|
} |
443 |
|
|
444 |
< |
/** Throws if workQueue is set to null */ |
444 |
> |
/** |
445 |
> |
* Constructor throws if workQueue is set to null |
446 |
> |
*/ |
447 |
|
public void testNullPointerException4() { |
448 |
|
try { |
449 |
< |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler()); |
449 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler()); |
450 |
|
shouldThrow(); |
451 |
|
} |
452 |
|
catch (NullPointerException success){} |
453 |
|
} |
454 |
|
|
455 |
< |
/** Throws if handler is set to null */ |
455 |
> |
/** |
456 |
> |
* Constructor throws if handler is set to null |
457 |
> |
*/ |
458 |
|
public void testNullPointerException5() { |
459 |
|
try { |
460 |
|
RejectedExecutionHandler r = null; |
465 |
|
} |
466 |
|
|
467 |
|
|
468 |
< |
/** Throws if corePoolSize argument is less than zero */ |
468 |
> |
/** |
469 |
> |
* Constructor throws if corePoolSize argument is less than zero |
470 |
> |
*/ |
471 |
|
public void testConstructor16() { |
472 |
|
try { |
473 |
< |
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
473 |
> |
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
474 |
|
shouldThrow(); |
475 |
|
} |
476 |
|
catch (IllegalArgumentException success){} |
477 |
|
} |
478 |
|
|
479 |
< |
/** Throws if maximumPoolSize is less than zero */ |
479 |
> |
/** |
480 |
> |
* Constructor throws if maximumPoolSize is less than zero |
481 |
> |
*/ |
482 |
|
public void testConstructor17() { |
483 |
|
try { |
484 |
< |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
484 |
> |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
485 |
|
shouldThrow(); |
486 |
|
} |
487 |
|
catch (IllegalArgumentException success){} |
488 |
|
} |
489 |
|
|
490 |
< |
/** Throws if maximumPoolSize is equal to zero */ |
490 |
> |
/** |
491 |
> |
* Constructor throws if maximumPoolSize is equal to zero |
492 |
> |
*/ |
493 |
|
public void testConstructor18() { |
494 |
|
try { |
495 |
< |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
495 |
> |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
496 |
|
shouldThrow(); |
497 |
|
} |
498 |
|
catch (IllegalArgumentException success){} |
499 |
|
} |
500 |
|
|
501 |
< |
/** Throws if keepAliveTime is less than zero */ |
501 |
> |
/** |
502 |
> |
* Constructor throws if keepAliveTime is less than zero |
503 |
> |
*/ |
504 |
|
public void testConstructor19() { |
505 |
|
try { |
506 |
< |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
506 |
> |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
507 |
|
shouldThrow(); |
508 |
|
} |
509 |
|
catch (IllegalArgumentException success){} |
510 |
|
} |
511 |
|
|
512 |
< |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
512 |
> |
/** |
513 |
> |
* Constructor throws if corePoolSize is greater than the maximumPoolSize |
514 |
> |
*/ |
515 |
|
public void testConstructor20() { |
516 |
|
try { |
517 |
< |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
517 |
> |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
518 |
|
shouldThrow(); |
519 |
|
} |
520 |
|
catch (IllegalArgumentException success){} |
521 |
|
} |
522 |
|
|
523 |
< |
/** Throws if workQueue is set to null */ |
523 |
> |
/** |
524 |
> |
* Constructor throws if workQueue is set to null |
525 |
> |
*/ |
526 |
|
public void testNullPointerException6() { |
527 |
|
try { |
528 |
< |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler()); |
528 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); |
529 |
|
shouldThrow(); |
530 |
|
} |
531 |
|
catch (NullPointerException success){} |
532 |
|
} |
533 |
|
|
534 |
< |
/** Throws if handler is set to null */ |
534 |
> |
/** |
535 |
> |
* Constructor throws if handler is set to null |
536 |
> |
*/ |
537 |
|
public void testNullPointerException7() { |
538 |
|
try { |
539 |
|
RejectedExecutionHandler r = null; |
540 |
< |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r); |
540 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r); |
541 |
|
shouldThrow(); |
542 |
|
} |
543 |
|
catch (NullPointerException success){} |
544 |
|
} |
545 |
|
|
546 |
< |
/** Throws if ThreadFactory is set top null */ |
546 |
> |
/** |
547 |
> |
* Constructor throws if ThreadFactory is set top null |
548 |
> |
*/ |
549 |
|
public void testNullPointerException8() { |
550 |
|
try { |
551 |
|
ThreadFactory f = null; |
552 |
< |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler()); |
552 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler()); |
553 |
|
shouldThrow(); |
554 |
|
} |
555 |
|
catch (NullPointerException successdn8){} |
557 |
|
|
558 |
|
|
559 |
|
/** |
560 |
< |
* execute will throw RejectedExcutionException |
518 |
< |
* ThreadPoolExecutor will throw one when more runnables are |
519 |
< |
* executed then will fit in the Queue. |
560 |
> |
* execute throws RejectedExecutionException if shutdown |
561 |
|
*/ |
562 |
|
public void testRejectedExecutionException() { |
563 |
|
ThreadPoolExecutor tpe = null; |
572 |
|
|
573 |
|
joinPool(tpe); |
574 |
|
} |
575 |
+ |
|
576 |
+ |
/** |
577 |
+ |
* execute throws RejectedExecutionException |
578 |
+ |
* if saturated. |
579 |
+ |
*/ |
580 |
+ |
public void testSaturatedExecute() { |
581 |
+ |
ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
582 |
+ |
try { |
583 |
+ |
|
584 |
+ |
for(int i = 0; i < 5; ++i){ |
585 |
+ |
p.execute(new MediumRunnable()); |
586 |
+ |
} |
587 |
+ |
shouldThrow(); |
588 |
+ |
} catch(RejectedExecutionException success){} |
589 |
+ |
joinPool(p); |
590 |
+ |
} |
591 |
+ |
|
592 |
+ |
/** |
593 |
+ |
* execute (null) throws NPE |
594 |
+ |
*/ |
595 |
+ |
public void testExecuteNull() { |
596 |
+ |
ThreadPoolExecutor tpe = null; |
597 |
+ |
try { |
598 |
+ |
tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
599 |
+ |
tpe.execute(null); |
600 |
+ |
shouldThrow(); |
601 |
+ |
} catch(NullPointerException success){} |
602 |
+ |
|
603 |
+ |
joinPool(tpe); |
604 |
+ |
} |
605 |
|
|
606 |
|
/** |
607 |
< |
* setCorePoolSize will throw IllegalArgumentException |
537 |
< |
* when given a negative |
607 |
> |
* setCorePoolSize of netaitev value throws IllegalArgumentException |
608 |
|
*/ |
609 |
|
public void testCorePoolSizeIllegalArgumentException() { |
610 |
|
ThreadPoolExecutor tpe = null; |
621 |
|
joinPool(tpe); |
622 |
|
} |
623 |
|
|
554 |
– |
|
624 |
|
/** |
625 |
< |
* setMaximumPoolSize(int) will throw IllegalArgumentException |
626 |
< |
* if given a value less the it's actual core pool size |
625 |
> |
* setMaximumPoolSize(int) throws IllegalArgumentException if |
626 |
> |
* given a value less the core pool size |
627 |
|
*/ |
628 |
|
public void testMaximumPoolSizeIllegalArgumentException() { |
629 |
|
ThreadPoolExecutor tpe = null; |
641 |
|
} |
642 |
|
|
643 |
|
/** |
644 |
< |
* setMaximumPoolSize will throw IllegalArgumentException |
645 |
< |
* if given a negative number |
644 |
> |
* setMaximumPoolSize throws IllegalArgumentException |
645 |
> |
* if given a negative value |
646 |
|
*/ |
647 |
|
public void testMaximumPoolSizeIllegalArgumentException2() { |
648 |
|
ThreadPoolExecutor tpe = null; |
661 |
|
|
662 |
|
|
663 |
|
/** |
664 |
< |
* setKeepAliveTime will throw IllegalArgumentException |
664 |
> |
* setKeepAliveTime throws IllegalArgumentException |
665 |
|
* when given a negative value |
666 |
|
*/ |
667 |
|
public void testKeepAliveTimeIllegalArgumentException() { |