36 |
|
/** |
37 |
|
* execute successfully executes a runnable |
38 |
|
*/ |
39 |
< |
public void testExecute(){ |
40 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
39 |
> |
public void testExecute() { |
40 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
41 |
|
try { |
42 |
< |
one.execute(new Runnable(){ |
43 |
< |
public void run(){ |
44 |
< |
try{ |
42 |
> |
p1.execute(new Runnable() { |
43 |
> |
public void run() { |
44 |
> |
try { |
45 |
|
Thread.sleep(SHORT_DELAY_MS); |
46 |
|
} catch(InterruptedException e){ |
47 |
< |
fail("unexpected exception"); |
47 |
> |
threadUnexpectedException(); |
48 |
|
} |
49 |
|
} |
50 |
|
}); |
51 |
|
Thread.sleep(SMALL_DELAY_MS); |
52 |
|
} catch(InterruptedException e){ |
53 |
< |
fail("unexpected exception"); |
53 |
> |
unexpectedException(); |
54 |
|
} |
55 |
< |
joinPool(one); |
55 |
> |
joinPool(p1); |
56 |
|
} |
57 |
|
|
58 |
|
/** |
59 |
|
* getActiveCount gives correct values |
60 |
|
*/ |
61 |
< |
public void testGetActiveCount(){ |
62 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
63 |
< |
assertEquals(0, two.getActiveCount()); |
64 |
< |
two.execute(new MediumRunnable()); |
65 |
< |
try{ |
61 |
> |
public void testGetActiveCount() { |
62 |
> |
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
63 |
> |
assertEquals(0, p2.getActiveCount()); |
64 |
> |
p2.execute(new MediumRunnable()); |
65 |
> |
try { |
66 |
|
Thread.sleep(SHORT_DELAY_MS); |
67 |
|
} catch(Exception e){ |
68 |
< |
fail("unexpected exception"); |
68 |
> |
unexpectedException(); |
69 |
|
} |
70 |
< |
assertEquals(1, two.getActiveCount()); |
71 |
< |
joinPool(two); |
70 |
> |
assertEquals(1, p2.getActiveCount()); |
71 |
> |
joinPool(p2); |
72 |
|
} |
73 |
|
|
74 |
|
/** |
75 |
|
* getCompleteTaskCount gives correct values |
76 |
|
*/ |
77 |
< |
public void testGetCompletedTaskCount(){ |
78 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
79 |
< |
assertEquals(0, two.getCompletedTaskCount()); |
80 |
< |
two.execute(new ShortRunnable()); |
81 |
< |
try{ |
77 |
> |
public void testGetCompletedTaskCount() { |
78 |
> |
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
79 |
> |
assertEquals(0, p2.getCompletedTaskCount()); |
80 |
> |
p2.execute(new ShortRunnable()); |
81 |
> |
try { |
82 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
83 |
|
} catch(Exception e){ |
84 |
< |
fail("unexpected exception"); |
84 |
> |
unexpectedException(); |
85 |
|
} |
86 |
< |
assertEquals(1, two.getCompletedTaskCount()); |
87 |
< |
two.shutdown(); |
88 |
< |
joinPool(two); |
86 |
> |
assertEquals(1, p2.getCompletedTaskCount()); |
87 |
> |
p2.shutdown(); |
88 |
> |
joinPool(p2); |
89 |
|
} |
90 |
|
|
91 |
|
/** |
92 |
|
* getCorePoolSize gives correct values |
93 |
|
*/ |
94 |
< |
public void testGetCorePoolSize(){ |
95 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
96 |
< |
assertEquals(1, one.getCorePoolSize()); |
97 |
< |
joinPool(one); |
94 |
> |
public void testGetCorePoolSize() { |
95 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
96 |
> |
assertEquals(1, p1.getCorePoolSize()); |
97 |
> |
joinPool(p1); |
98 |
|
} |
99 |
|
|
100 |
|
/** |
101 |
|
* getKeepAliveTime gives correct values |
102 |
|
*/ |
103 |
< |
public void testGetKeepAliveTime(){ |
104 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
105 |
< |
assertEquals(1, two.getKeepAliveTime(TimeUnit.SECONDS)); |
106 |
< |
joinPool(two); |
103 |
> |
public void testGetKeepAliveTime() { |
104 |
> |
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
105 |
> |
assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS)); |
106 |
> |
joinPool(p2); |
107 |
|
} |
108 |
|
|
109 |
|
/** |
110 |
|
* getLargestPoolSize gives correct values |
111 |
|
*/ |
112 |
< |
public void testGetLargestPoolSize(){ |
113 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
112 |
> |
public void testGetLargestPoolSize() { |
113 |
> |
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
114 |
|
try { |
115 |
< |
assertEquals(0, two.getLargestPoolSize()); |
116 |
< |
two.execute(new MediumRunnable()); |
117 |
< |
two.execute(new MediumRunnable()); |
115 |
> |
assertEquals(0, p2.getLargestPoolSize()); |
116 |
> |
p2.execute(new MediumRunnable()); |
117 |
> |
p2.execute(new MediumRunnable()); |
118 |
|
Thread.sleep(SHORT_DELAY_MS); |
119 |
< |
assertEquals(2, two.getLargestPoolSize()); |
119 |
> |
assertEquals(2, p2.getLargestPoolSize()); |
120 |
|
} catch(Exception e){ |
121 |
< |
fail("unexpected exception"); |
121 |
> |
unexpectedException(); |
122 |
|
} |
123 |
< |
joinPool(two); |
123 |
> |
joinPool(p2); |
124 |
|
} |
125 |
|
|
126 |
|
/** |
127 |
|
* getMaximumPoolSize gives correct values |
128 |
|
*/ |
129 |
< |
public void testGetMaximumPoolSize(){ |
130 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
131 |
< |
assertEquals(2, two.getMaximumPoolSize()); |
132 |
< |
joinPool(two); |
129 |
> |
public void testGetMaximumPoolSize() { |
130 |
> |
ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
131 |
> |
assertEquals(2, p2.getMaximumPoolSize()); |
132 |
> |
joinPool(p2); |
133 |
|
} |
134 |
|
|
135 |
|
/** |
136 |
|
* getPoolSize gives correct values |
137 |
|
*/ |
138 |
< |
public void testGetPoolSize(){ |
139 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
140 |
< |
assertEquals(0, one.getPoolSize()); |
141 |
< |
one.execute(new MediumRunnable()); |
142 |
< |
assertEquals(1, one.getPoolSize()); |
143 |
< |
joinPool(one); |
138 |
> |
public void testGetPoolSize() { |
139 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
140 |
> |
assertEquals(0, p1.getPoolSize()); |
141 |
> |
p1.execute(new MediumRunnable()); |
142 |
> |
assertEquals(1, p1.getPoolSize()); |
143 |
> |
joinPool(p1); |
144 |
|
} |
145 |
|
|
146 |
|
/** |
147 |
|
* getTaskCount gives correct values |
148 |
|
*/ |
149 |
< |
public void testGetTaskCount(){ |
150 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
149 |
> |
public void testGetTaskCount() { |
150 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
151 |
|
try { |
152 |
< |
assertEquals(0, one.getTaskCount()); |
153 |
< |
one.execute(new MediumRunnable()); |
152 |
> |
assertEquals(0, p1.getTaskCount()); |
153 |
> |
p1.execute(new MediumRunnable()); |
154 |
|
Thread.sleep(SHORT_DELAY_MS); |
155 |
< |
assertEquals(1, one.getTaskCount()); |
155 |
> |
assertEquals(1, p1.getTaskCount()); |
156 |
|
} catch(Exception e){ |
157 |
< |
fail("unexpected exception"); |
157 |
> |
unexpectedException(); |
158 |
|
} |
159 |
< |
joinPool(one); |
159 |
> |
joinPool(p1); |
160 |
|
} |
161 |
|
|
162 |
|
/** |
163 |
|
* isShutDown gives correct values |
164 |
|
*/ |
165 |
< |
public void testIsShutdown(){ |
165 |
> |
public void testIsShutdown() { |
166 |
|
|
167 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
168 |
< |
assertFalse(one.isShutdown()); |
169 |
< |
one.shutdown(); |
170 |
< |
assertTrue(one.isShutdown()); |
171 |
< |
joinPool(one); |
167 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
168 |
> |
assertFalse(p1.isShutdown()); |
169 |
> |
p1.shutdown(); |
170 |
> |
assertTrue(p1.isShutdown()); |
171 |
> |
joinPool(p1); |
172 |
|
} |
173 |
|
|
174 |
|
|
177 |
|
* Makes sure termination does not take an innapropriate |
178 |
|
* amount of time |
179 |
|
*/ |
180 |
< |
public void testIsTerminated(){ |
181 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
180 |
> |
public void testIsTerminated() { |
181 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
182 |
|
try { |
183 |
< |
one.execute(new MediumRunnable()); |
183 |
> |
p1.execute(new MediumRunnable()); |
184 |
|
} finally { |
185 |
< |
one.shutdown(); |
185 |
> |
p1.shutdown(); |
186 |
|
} |
187 |
|
try { |
188 |
< |
assertTrue(one.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
189 |
< |
assertTrue(one.isTerminated()); |
188 |
> |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
189 |
> |
assertTrue(p1.isTerminated()); |
190 |
|
} catch(Exception e){ |
191 |
< |
fail("unexpected exception"); |
191 |
> |
unexpectedException(); |
192 |
> |
} |
193 |
> |
} |
194 |
> |
|
195 |
> |
/** |
196 |
> |
* isTerminating gives correct values |
197 |
> |
*/ |
198 |
> |
public void testIsTerminating() { |
199 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
200 |
> |
assertFalse(p1.isTerminating()); |
201 |
> |
try { |
202 |
> |
p1.execute(new SmallRunnable()); |
203 |
> |
assertFalse(p1.isTerminating()); |
204 |
> |
} finally { |
205 |
> |
p1.shutdown(); |
206 |
> |
} |
207 |
> |
try { |
208 |
> |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
209 |
> |
assertTrue(p1.isTerminated()); |
210 |
> |
assertFalse(p1.isTerminating()); |
211 |
> |
} catch(Exception e){ |
212 |
> |
unexpectedException(); |
213 |
|
} |
214 |
|
} |
215 |
|
|
217 |
|
* purge correctly removes cancelled tasks |
218 |
|
* from the queue |
219 |
|
*/ |
220 |
< |
public void testPurge(){ |
221 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
220 |
> |
public void testPurge() { |
221 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
222 |
|
CancellableTask[] tasks = new CancellableTask[5]; |
223 |
|
for(int i = 0; i < 5; i++){ |
224 |
|
tasks[i] = new CancellableTask(new MediumPossiblyInterruptedRunnable()); |
225 |
< |
one.execute(tasks[i]); |
225 |
> |
p1.execute(tasks[i]); |
226 |
|
} |
227 |
|
tasks[4].cancel(true); |
228 |
|
tasks[3].cancel(true); |
229 |
< |
one.purge(); |
230 |
< |
long count = one.getTaskCount(); |
229 |
> |
p1.purge(); |
230 |
> |
long count = p1.getTaskCount(); |
231 |
|
assertTrue(count >= 2 && count < 5); |
232 |
< |
joinPool(one); |
232 |
> |
joinPool(p1); |
233 |
|
} |
234 |
|
|
235 |
|
/** |
236 |
|
* shutDownNow returns a list |
237 |
|
* containing the correct number of elements |
238 |
|
*/ |
239 |
< |
public void testShutDownNow(){ |
240 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
239 |
> |
public void testShutDownNow() { |
240 |
> |
ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
241 |
|
List l; |
242 |
|
try { |
243 |
|
for(int i = 0; i < 5; i++) |
244 |
< |
one.execute(new MediumPossiblyInterruptedRunnable()); |
244 |
> |
p1.execute(new MediumPossiblyInterruptedRunnable()); |
245 |
|
} |
246 |
|
finally { |
247 |
< |
l = one.shutdownNow(); |
247 |
> |
l = p1.shutdownNow(); |
248 |
|
} |
249 |
< |
assertTrue(one.isShutdown()); |
249 |
> |
assertTrue(p1.isShutdown()); |
250 |
|
assertTrue(l.size() <= 4); |
251 |
|
} |
252 |
|
|
255 |
|
|
256 |
|
/** Throws if corePoolSize argument is less than zero */ |
257 |
|
public void testConstructor1() { |
258 |
< |
try{ |
258 |
> |
try { |
259 |
|
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
260 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
260 |
> |
shouldThrow(); |
261 |
|
} |
262 |
|
catch (IllegalArgumentException success){} |
263 |
|
} |
264 |
|
|
265 |
|
/** Throws if maximumPoolSize is less than zero */ |
266 |
|
public void testConstructor2() { |
267 |
< |
try{ |
267 |
> |
try { |
268 |
|
new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
269 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
269 |
> |
shouldThrow(); |
270 |
|
} |
271 |
|
catch (IllegalArgumentException success){} |
272 |
|
} |
273 |
|
|
274 |
|
/** Throws if maximumPoolSize is equal to zero */ |
275 |
|
public void testConstructor3() { |
276 |
< |
try{ |
276 |
> |
try { |
277 |
|
new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
278 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
278 |
> |
shouldThrow(); |
279 |
|
} |
280 |
|
catch (IllegalArgumentException success){} |
281 |
|
} |
282 |
|
|
283 |
|
/** Throws if keepAliveTime is less than zero */ |
284 |
|
public void testConstructor4() { |
285 |
< |
try{ |
285 |
> |
try { |
286 |
|
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
287 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
287 |
> |
shouldThrow(); |
288 |
|
} |
289 |
|
catch (IllegalArgumentException success){} |
290 |
|
} |
291 |
|
|
292 |
|
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
293 |
|
public void testConstructor5() { |
294 |
< |
try{ |
294 |
> |
try { |
295 |
|
new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
296 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
296 |
> |
shouldThrow(); |
297 |
|
} |
298 |
|
catch (IllegalArgumentException success){} |
299 |
|
} |
300 |
|
|
301 |
|
/** Throws if workQueue is set to null */ |
302 |
|
public void testNullPointerException() { |
303 |
< |
try{ |
303 |
> |
try { |
304 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null); |
305 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
305 |
> |
shouldThrow(); |
306 |
|
} |
307 |
|
catch (NullPointerException success){} |
308 |
|
} |
311 |
|
|
312 |
|
/** Throws if corePoolSize argument is less than zero */ |
313 |
|
public void testConstructor6() { |
314 |
< |
try{ |
314 |
> |
try { |
315 |
|
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
316 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
316 |
> |
shouldThrow(); |
317 |
|
} catch (IllegalArgumentException success){} |
318 |
|
} |
319 |
|
|
320 |
|
/** Throws if maximumPoolSize is less than zero */ |
321 |
|
public void testConstructor7() { |
322 |
< |
try{ |
322 |
> |
try { |
323 |
|
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
324 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
324 |
> |
shouldThrow(); |
325 |
|
} |
326 |
|
catch (IllegalArgumentException success){} |
327 |
|
} |
328 |
|
|
329 |
|
/** Throws if maximumPoolSize is equal to zero */ |
330 |
|
public void testConstructor8() { |
331 |
< |
try{ |
331 |
> |
try { |
332 |
|
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
333 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
333 |
> |
shouldThrow(); |
334 |
|
} |
335 |
|
catch (IllegalArgumentException success){} |
336 |
|
} |
337 |
|
|
338 |
|
/** Throws if keepAliveTime is less than zero */ |
339 |
|
public void testConstructor9() { |
340 |
< |
try{ |
340 |
> |
try { |
341 |
|
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
342 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
342 |
> |
shouldThrow(); |
343 |
|
} |
344 |
|
catch (IllegalArgumentException success){} |
345 |
|
} |
346 |
|
|
347 |
|
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
348 |
|
public void testConstructor10() { |
349 |
< |
try{ |
349 |
> |
try { |
350 |
|
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
351 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
351 |
> |
shouldThrow(); |
352 |
|
} |
353 |
|
catch (IllegalArgumentException success){} |
354 |
|
} |
355 |
|
|
356 |
|
/** Throws if workQueue is set to null */ |
357 |
|
public void testNullPointerException2() { |
358 |
< |
try{ |
358 |
> |
try { |
359 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory()); |
360 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
360 |
> |
shouldThrow(); |
361 |
|
} |
362 |
|
catch (NullPointerException success){} |
363 |
|
} |
364 |
|
|
365 |
|
/** Throws if threadFactory is set to null */ |
366 |
|
public void testNullPointerException3() { |
367 |
< |
try{ |
367 |
> |
try { |
368 |
|
ThreadFactory f = null; |
369 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
370 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
370 |
> |
shouldThrow(); |
371 |
|
} |
372 |
|
catch (NullPointerException success){} |
373 |
|
} |
375 |
|
|
376 |
|
/** Throws if corePoolSize argument is less than zero */ |
377 |
|
public void testConstructor11() { |
378 |
< |
try{ |
378 |
> |
try { |
379 |
|
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
380 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
380 |
> |
shouldThrow(); |
381 |
|
} |
382 |
|
catch (IllegalArgumentException success){} |
383 |
|
} |
384 |
|
|
385 |
|
/** Throws if maximumPoolSize is less than zero */ |
386 |
|
public void testConstructor12() { |
387 |
< |
try{ |
387 |
> |
try { |
388 |
|
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
389 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
389 |
> |
shouldThrow(); |
390 |
|
} |
391 |
|
catch (IllegalArgumentException success){} |
392 |
|
} |
393 |
|
|
394 |
|
/** Throws if maximumPoolSize is equal to zero */ |
395 |
|
public void testConstructor13() { |
396 |
< |
try{ |
396 |
> |
try { |
397 |
|
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
398 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
398 |
> |
shouldThrow(); |
399 |
|
} |
400 |
|
catch (IllegalArgumentException success){} |
401 |
|
} |
402 |
|
|
403 |
|
/** Throws if keepAliveTime is less than zero */ |
404 |
|
public void testConstructor14() { |
405 |
< |
try{ |
405 |
> |
try { |
406 |
|
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
407 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
407 |
> |
shouldThrow(); |
408 |
|
} |
409 |
|
catch (IllegalArgumentException success){} |
410 |
|
} |
411 |
|
|
412 |
|
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
413 |
|
public void testConstructor15() { |
414 |
< |
try{ |
414 |
> |
try { |
415 |
|
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
416 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
416 |
> |
shouldThrow(); |
417 |
|
} |
418 |
|
catch (IllegalArgumentException success){} |
419 |
|
} |
420 |
|
|
421 |
|
/** Throws if workQueue is set to null */ |
422 |
|
public void testNullPointerException4() { |
423 |
< |
try{ |
423 |
> |
try { |
424 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler()); |
425 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
425 |
> |
shouldThrow(); |
426 |
|
} |
427 |
|
catch (NullPointerException success){} |
428 |
|
} |
429 |
|
|
430 |
|
/** Throws if handler is set to null */ |
431 |
|
public void testNullPointerException5() { |
432 |
< |
try{ |
432 |
> |
try { |
433 |
|
RejectedExecutionHandler r = null; |
434 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
435 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
435 |
> |
shouldThrow(); |
436 |
|
} |
437 |
|
catch (NullPointerException success){} |
438 |
|
} |
440 |
|
|
441 |
|
/** Throws if corePoolSize argument is less than zero */ |
442 |
|
public void testConstructor16() { |
443 |
< |
try{ |
443 |
> |
try { |
444 |
|
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
445 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
445 |
> |
shouldThrow(); |
446 |
|
} |
447 |
|
catch (IllegalArgumentException success){} |
448 |
|
} |
449 |
|
|
450 |
|
/** Throws if maximumPoolSize is less than zero */ |
451 |
|
public void testConstructor17() { |
452 |
< |
try{ |
452 |
> |
try { |
453 |
|
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
454 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
454 |
> |
shouldThrow(); |
455 |
|
} |
456 |
|
catch (IllegalArgumentException success){} |
457 |
|
} |
458 |
|
|
459 |
|
/** Throws if maximumPoolSize is equal to zero */ |
460 |
|
public void testConstructor18() { |
461 |
< |
try{ |
461 |
> |
try { |
462 |
|
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
463 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
463 |
> |
shouldThrow(); |
464 |
|
} |
465 |
|
catch (IllegalArgumentException success){} |
466 |
|
} |
467 |
|
|
468 |
|
/** Throws if keepAliveTime is less than zero */ |
469 |
|
public void testConstructor19() { |
470 |
< |
try{ |
470 |
> |
try { |
471 |
|
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
472 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
472 |
> |
shouldThrow(); |
473 |
|
} |
474 |
|
catch (IllegalArgumentException success){} |
475 |
|
} |
476 |
|
|
477 |
|
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
478 |
|
public void testConstructor20() { |
479 |
< |
try{ |
479 |
> |
try { |
480 |
|
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
481 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
481 |
> |
shouldThrow(); |
482 |
|
} |
483 |
|
catch (IllegalArgumentException success){} |
484 |
|
} |
485 |
|
|
486 |
|
/** Throws if workQueue is set to null */ |
487 |
|
public void testNullPointerException6() { |
488 |
< |
try{ |
488 |
> |
try { |
489 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler()); |
490 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
490 |
> |
shouldThrow(); |
491 |
|
} |
492 |
|
catch (NullPointerException success){} |
493 |
|
} |
494 |
|
|
495 |
|
/** Throws if handler is set to null */ |
496 |
|
public void testNullPointerException7() { |
497 |
< |
try{ |
497 |
> |
try { |
498 |
|
RejectedExecutionHandler r = null; |
499 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r); |
500 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
500 |
> |
shouldThrow(); |
501 |
|
} |
502 |
|
catch (NullPointerException success){} |
503 |
|
} |
504 |
|
|
505 |
|
/** Throws if ThreadFactory is set top null */ |
506 |
|
public void testNullPointerException8() { |
507 |
< |
try{ |
507 |
> |
try { |
508 |
|
ThreadFactory f = null; |
509 |
|
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler()); |
510 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
510 |
> |
shouldThrow(); |
511 |
|
} |
512 |
|
catch (NullPointerException successdn8){} |
513 |
|
} |
518 |
|
* ThreadPoolExecutor will throw one when more runnables are |
519 |
|
* executed then will fit in the Queue. |
520 |
|
*/ |
521 |
< |
public void testRejectedExecutionException(){ |
521 |
> |
public void testRejectedExecutionException() { |
522 |
|
ThreadPoolExecutor tpe = null; |
523 |
< |
try{ |
523 |
> |
try { |
524 |
|
tpe = new ThreadPoolExecutor(1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
525 |
|
} catch(Exception e){} |
526 |
|
tpe.shutdown(); |
527 |
< |
try{ |
527 |
> |
try { |
528 |
|
tpe.execute(new NoOpRunnable()); |
529 |
< |
fail("ThreadPoolExecutor - void execute(Runnable) should throw RejectedExecutionException"); |
529 |
> |
shouldThrow(); |
530 |
|
} catch(RejectedExecutionException success){} |
531 |
|
|
532 |
|
joinPool(tpe); |
536 |
|
* setCorePoolSize will throw IllegalArgumentException |
537 |
|
* when given a negative |
538 |
|
*/ |
539 |
< |
public void testCorePoolSizeIllegalArgumentException(){ |
539 |
> |
public void testCorePoolSizeIllegalArgumentException() { |
540 |
|
ThreadPoolExecutor tpe = null; |
541 |
< |
try{ |
541 |
> |
try { |
542 |
|
tpe = new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
543 |
|
} catch(Exception e){} |
544 |
< |
try{ |
544 |
> |
try { |
545 |
|
tpe.setCorePoolSize(-1); |
546 |
< |
fail("ThreadPoolExecutor - void setCorePoolSize(int) should throw IllegalArgumentException"); |
546 |
> |
shouldThrow(); |
547 |
|
} catch(IllegalArgumentException success){ |
548 |
|
} finally { |
549 |
|
tpe.shutdown(); |
556 |
|
* setMaximumPoolSize(int) will throw IllegalArgumentException |
557 |
|
* if given a value less the it's actual core pool size |
558 |
|
*/ |
559 |
< |
public void testMaximumPoolSizeIllegalArgumentException(){ |
559 |
> |
public void testMaximumPoolSizeIllegalArgumentException() { |
560 |
|
ThreadPoolExecutor tpe = null; |
561 |
< |
try{ |
561 |
> |
try { |
562 |
|
tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
563 |
|
} catch(Exception e){} |
564 |
< |
try{ |
564 |
> |
try { |
565 |
|
tpe.setMaximumPoolSize(1); |
566 |
< |
fail("ThreadPoolExecutor - void setMaximumPoolSize(int) should throw IllegalArgumentException"); |
566 |
> |
shouldThrow(); |
567 |
|
} catch(IllegalArgumentException success){ |
568 |
|
} finally { |
569 |
|
tpe.shutdown(); |
575 |
|
* setMaximumPoolSize will throw IllegalArgumentException |
576 |
|
* if given a negative number |
577 |
|
*/ |
578 |
< |
public void testMaximumPoolSizeIllegalArgumentException2(){ |
578 |
> |
public void testMaximumPoolSizeIllegalArgumentException2() { |
579 |
|
ThreadPoolExecutor tpe = null; |
580 |
< |
try{ |
580 |
> |
try { |
581 |
|
tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
582 |
|
} catch(Exception e){} |
583 |
< |
try{ |
583 |
> |
try { |
584 |
|
tpe.setMaximumPoolSize(-1); |
585 |
< |
fail("ThreadPoolExecutor - void setMaximumPoolSize(int) should throw IllegalArgumentException"); |
585 |
> |
shouldThrow(); |
586 |
|
} catch(IllegalArgumentException success){ |
587 |
|
} finally { |
588 |
|
tpe.shutdown(); |
595 |
|
* setKeepAliveTime will throw IllegalArgumentException |
596 |
|
* when given a negative value |
597 |
|
*/ |
598 |
< |
public void testKeepAliveTimeIllegalArgumentException(){ |
598 |
> |
public void testKeepAliveTimeIllegalArgumentException() { |
599 |
|
ThreadPoolExecutor tpe = null; |
600 |
< |
try{ |
600 |
> |
try { |
601 |
|
tpe = new ThreadPoolExecutor(2,3,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
602 |
|
} catch(Exception e){} |
603 |
|
|
604 |
< |
try{ |
604 |
> |
try { |
605 |
|
tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); |
606 |
< |
fail("ThreadPoolExecutor - void setKeepAliveTime(long, TimeUnit) should throw IllegalArgumentException"); |
606 |
> |
shouldThrow(); |
607 |
|
} catch(IllegalArgumentException success){ |
608 |
|
} finally { |
609 |
|
tpe.shutdown(); |