9 |
|
import junit.framework.*; |
10 |
|
import java.util.List; |
11 |
|
|
12 |
< |
public class ThreadPoolExecutorTest extends TestCase{ |
12 |
> |
public class ThreadPoolExecutorTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
|
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
16 |
– |
|
17 |
– |
|
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ThreadPoolExecutorTest.class); |
18 |
|
} |
19 |
|
|
20 |
< |
private static long SHORT_DELAY_MS = 100; |
21 |
< |
private static long MEDIUM_DELAY_MS = 1000; |
22 |
< |
private static long LONG_DELAY_MS = 10000; |
23 |
< |
|
26 |
< |
//---- testThread class to implement ThreadFactory for use in constructors |
27 |
< |
static class testThread implements ThreadFactory{ |
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 |
|
} |
28 |
|
|
29 |
< |
//---- testReject class to implement RejectedExecutionHandler for use in the constructors |
30 |
< |
static class testReject implements RejectedExecutionHandler{ |
29 |
> |
/** |
30 |
> |
* For use as RejectedExecutionHandler in constructors |
31 |
> |
*/ |
32 |
> |
static class MyREHandler implements RejectedExecutionHandler{ |
33 |
|
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){} |
34 |
|
} |
37 |
– |
|
38 |
– |
public Runnable newRunnable(){ |
39 |
– |
return new Runnable(){ |
40 |
– |
public void run(){ |
41 |
– |
try{Thread.sleep(MEDIUM_DELAY_MS); |
42 |
– |
} catch(Exception e){ |
43 |
– |
} |
44 |
– |
} |
45 |
– |
}; |
46 |
– |
} |
47 |
– |
|
35 |
|
|
36 |
|
/** |
37 |
< |
* Test to verify that execute successfully executes a runnable |
37 |
> |
* execute successfully executes a runnable |
38 |
|
*/ |
39 |
< |
public void testExecute(){ |
40 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, 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(SHORT_DELAY_MS * 2); |
51 |
> |
Thread.sleep(SMALL_DELAY_MS); |
52 |
|
} catch(InterruptedException e){ |
53 |
< |
fail("unexpected exception"); |
54 |
< |
} finally { |
55 |
< |
one.shutdown(); |
69 |
< |
} |
53 |
> |
unexpectedException(); |
54 |
> |
} |
55 |
> |
joinPool(p1); |
56 |
|
} |
57 |
|
|
58 |
|
/** |
59 |
< |
* Test to verify getActiveCount gives correct values |
59 |
> |
* getActiveCount gives correct values |
60 |
|
*/ |
61 |
< |
public void testGetActiveCount(){ |
62 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
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 |
< |
assertEquals(0, two.getActiveCount()); |
67 |
< |
two.execute(newRunnable()); |
68 |
< |
try{Thread.sleep(10);} catch(Exception e){} |
81 |
< |
assertEquals(1, two.getActiveCount()); |
82 |
< |
} finally { |
83 |
< |
two.shutdown(); |
66 |
> |
Thread.sleep(SHORT_DELAY_MS); |
67 |
> |
} catch(Exception e){ |
68 |
> |
unexpectedException(); |
69 |
|
} |
70 |
+ |
assertEquals(1, p2.getActiveCount()); |
71 |
+ |
joinPool(p2); |
72 |
|
} |
73 |
|
|
74 |
|
/** |
75 |
< |
* Test to verify getCompleteTaskCount gives correct values |
75 |
> |
* getCompleteTaskCount gives correct values |
76 |
|
*/ |
77 |
< |
public void testGetCompletedTaskCount(){ |
78 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
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 |
< |
assertEquals(0, two.getCompletedTaskCount()); |
83 |
< |
two.execute(newRunnable()); |
84 |
< |
try{Thread.sleep(2000);} catch(Exception e){} |
96 |
< |
assertEquals(1, two.getCompletedTaskCount()); |
97 |
< |
} finally { |
98 |
< |
two.shutdown(); |
82 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
83 |
> |
} catch(Exception e){ |
84 |
> |
unexpectedException(); |
85 |
|
} |
86 |
+ |
assertEquals(1, p2.getCompletedTaskCount()); |
87 |
+ |
p2.shutdown(); |
88 |
+ |
joinPool(p2); |
89 |
|
} |
90 |
|
|
91 |
|
/** |
92 |
< |
* Test to verify getCorePoolSize gives correct values |
92 |
> |
* getCorePoolSize gives correct values |
93 |
|
*/ |
94 |
< |
public void testGetCorePoolSize(){ |
95 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
96 |
< |
try { |
97 |
< |
assertEquals(1, one.getCorePoolSize()); |
109 |
< |
} finally { |
110 |
< |
one.shutdown(); |
111 |
< |
} |
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 |
< |
* Test to verify getKeepAliveTime gives correct values |
101 |
> |
* getKeepAliveTime gives correct values |
102 |
|
*/ |
103 |
< |
public void testGetKeepAliveTime(){ |
104 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
105 |
< |
try { |
106 |
< |
assertEquals(1, two.getKeepAliveTime(TimeUnit.SECONDS)); |
121 |
< |
} finally { |
122 |
< |
two.shutdown(); |
123 |
< |
} |
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 |
< |
* Test to verify getLargestPoolSize gives correct values |
110 |
> |
* getLargestPoolSize gives correct values |
111 |
|
*/ |
112 |
< |
public void testGetLargestPoolSize(){ |
113 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, 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(newRunnable()); |
117 |
< |
two.execute(newRunnable()); |
118 |
< |
try{Thread.sleep(SHORT_DELAY_MS);} catch(Exception e){} |
119 |
< |
assertEquals(2, two.getLargestPoolSize()); |
120 |
< |
} finally { |
121 |
< |
two.shutdown(); |
122 |
< |
} |
115 |
> |
assertEquals(0, p2.getLargestPoolSize()); |
116 |
> |
p2.execute(new MediumRunnable()); |
117 |
> |
p2.execute(new MediumRunnable()); |
118 |
> |
Thread.sleep(SHORT_DELAY_MS); |
119 |
> |
assertEquals(2, p2.getLargestPoolSize()); |
120 |
> |
} catch(Exception e){ |
121 |
> |
unexpectedException(); |
122 |
> |
} |
123 |
> |
joinPool(p2); |
124 |
|
} |
125 |
|
|
126 |
|
/** |
127 |
< |
* Test to verify getMaximumPoolSize gives correct values |
127 |
> |
* getMaximumPoolSize gives correct values |
128 |
|
*/ |
129 |
< |
public void testGetMaximumPoolSize(){ |
130 |
< |
ThreadPoolExecutor two = new ThreadPoolExecutor(2, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
131 |
< |
try { |
132 |
< |
assertEquals(2, two.getMaximumPoolSize()); |
149 |
< |
} finally { |
150 |
< |
two.shutdown(); |
151 |
< |
} |
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 |
< |
* Test to verify getPoolSize gives correct values |
136 |
> |
* getPoolSize gives correct values |
137 |
|
*/ |
138 |
< |
public void testGetPoolSize(){ |
139 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
140 |
< |
try { |
141 |
< |
assertEquals(0, one.getPoolSize()); |
142 |
< |
one.execute(newRunnable()); |
143 |
< |
assertEquals(1, one.getPoolSize()); |
163 |
< |
} finally { |
164 |
< |
one.shutdown(); |
165 |
< |
} |
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 |
< |
* Test to verify getTaskCount gives correct values |
147 |
> |
* getTaskCount gives correct values |
148 |
|
*/ |
149 |
< |
public void testGetTaskCount(){ |
150 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, 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 |
< |
for(int i = 0; i < 5; i++) |
154 |
< |
one.execute(newRunnable()); |
155 |
< |
try{Thread.sleep(SHORT_DELAY_MS);} catch(Exception e){} |
156 |
< |
assertEquals(5, one.getTaskCount()); |
157 |
< |
} finally { |
158 |
< |
one.shutdown(); |
159 |
< |
} |
152 |
> |
assertEquals(0, p1.getTaskCount()); |
153 |
> |
p1.execute(new MediumRunnable()); |
154 |
> |
Thread.sleep(SHORT_DELAY_MS); |
155 |
> |
assertEquals(1, p1.getTaskCount()); |
156 |
> |
} catch(Exception e){ |
157 |
> |
unexpectedException(); |
158 |
> |
} |
159 |
> |
joinPool(p1); |
160 |
|
} |
161 |
|
|
162 |
|
/** |
163 |
< |
* Test to verify isShutDown gives correct values |
163 |
> |
* isShutDown gives correct values |
164 |
|
*/ |
165 |
< |
public void testIsShutdown(){ |
165 |
> |
public void testIsShutdown() { |
166 |
|
|
167 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
168 |
< |
try { |
169 |
< |
assertFalse(one.isShutdown()); |
170 |
< |
} |
171 |
< |
finally { |
194 |
< |
one.shutdown(); |
195 |
< |
} |
196 |
< |
assertTrue(one.isShutdown()); |
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 |
|
|
175 |
|
/** |
176 |
< |
* Test to verify isTerminated gives correct values |
176 |
> |
* isTerminated gives correct values |
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, 1, TimeUnit.SECONDS, 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(newRunnable()); |
183 |
> |
p1.execute(new MediumRunnable()); |
184 |
|
} finally { |
185 |
< |
one.shutdown(); |
185 |
> |
p1.shutdown(); |
186 |
|
} |
187 |
< |
boolean flag = false; |
188 |
< |
try{ |
189 |
< |
flag = one.awaitTermination(10, TimeUnit.SECONDS); |
190 |
< |
} catch(Exception e){} |
191 |
< |
assertTrue(one.isTerminated()); |
192 |
< |
if(!flag) |
218 |
< |
fail("ThreadPoolExecutor - thread pool did not terminate within suitable timeframe"); |
187 |
> |
try { |
188 |
> |
assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
189 |
> |
assertTrue(p1.isTerminated()); |
190 |
> |
} catch(Exception e){ |
191 |
> |
unexpectedException(); |
192 |
> |
} |
193 |
|
} |
194 |
|
|
195 |
|
/** |
196 |
< |
* Test to verify that purge correctly removes cancelled tasks |
223 |
< |
* from the queue |
196 |
> |
* isTerminating gives correct values |
197 |
|
*/ |
198 |
< |
public void testPurge(){ |
199 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
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 |
< |
CancellableTask[] tasks = new CancellableTask[5]; |
203 |
< |
for(int i = 0; i < 5; i++){ |
230 |
< |
tasks[i] = new CancellableTask(newRunnable()); |
231 |
< |
one.execute(tasks[i]); |
232 |
< |
} |
233 |
< |
tasks[4].cancel(true); |
234 |
< |
tasks[3].cancel(true); |
235 |
< |
one.purge(); |
236 |
< |
long count = one.getTaskCount(); |
237 |
< |
assertTrue(count >= 2 && count < 5); |
202 |
> |
p1.execute(new SmallRunnable()); |
203 |
> |
assertFalse(p1.isTerminating()); |
204 |
|
} finally { |
205 |
< |
one.shutdown(); |
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 |
+ |
|
216 |
+ |
/** |
217 |
+ |
* purge correctly removes cancelled tasks |
218 |
+ |
* from the queue |
219 |
+ |
*/ |
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 |
+ |
p1.execute(tasks[i]); |
226 |
+ |
} |
227 |
+ |
tasks[4].cancel(true); |
228 |
+ |
tasks[3].cancel(true); |
229 |
+ |
p1.purge(); |
230 |
+ |
long count = p1.getTaskCount(); |
231 |
+ |
assertTrue(count >= 2 && count < 5); |
232 |
+ |
joinPool(p1); |
233 |
|
} |
234 |
|
|
235 |
|
/** |
236 |
< |
* Test to verify shutDownNow returns a list |
236 |
> |
* shutDownNow returns a list |
237 |
|
* containing the correct number of elements |
238 |
|
*/ |
239 |
< |
public void testShutDownNow(){ |
240 |
< |
ThreadPoolExecutor one = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, 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(newRunnable()); |
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 |
|
|
261 |
– |
|
262 |
– |
|
263 |
– |
|
264 |
– |
|
265 |
– |
|
253 |
|
// Exception Tests |
254 |
|
|
255 |
|
|
256 |
< |
//---- Tests if corePoolSize argument is less than zero |
256 |
> |
/** Throws if corePoolSize argument is less than zero */ |
257 |
|
public void testConstructor1() { |
258 |
< |
try{ |
259 |
< |
new ThreadPoolExecutor(-1,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
260 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
258 |
> |
try { |
259 |
> |
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
260 |
> |
shouldThrow(); |
261 |
|
} |
262 |
< |
catch (IllegalArgumentException i){} |
262 |
> |
catch (IllegalArgumentException success){} |
263 |
|
} |
264 |
|
|
265 |
< |
//---- Tests if maximumPoolSize is less than zero |
265 |
> |
/** Throws if maximumPoolSize is less than zero */ |
266 |
|
public void testConstructor2() { |
267 |
< |
try{ |
268 |
< |
new ThreadPoolExecutor(1,-1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
269 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
267 |
> |
try { |
268 |
> |
new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
269 |
> |
shouldThrow(); |
270 |
|
} |
271 |
< |
catch (IllegalArgumentException i2){} |
271 |
> |
catch (IllegalArgumentException success){} |
272 |
|
} |
273 |
|
|
274 |
< |
//---- Tests if maximumPoolSize is equal to zero |
274 |
> |
/** Throws if maximumPoolSize is equal to zero */ |
275 |
|
public void testConstructor3() { |
276 |
< |
try{ |
277 |
< |
new ThreadPoolExecutor(1,0,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
278 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
276 |
> |
try { |
277 |
> |
new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
278 |
> |
shouldThrow(); |
279 |
|
} |
280 |
< |
catch (IllegalArgumentException i3){} |
280 |
> |
catch (IllegalArgumentException success){} |
281 |
|
} |
282 |
|
|
283 |
< |
//---- Tests if keepAliveTime is less than zero |
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 i4){} |
289 |
> |
catch (IllegalArgumentException success){} |
290 |
|
} |
291 |
|
|
292 |
< |
//---- Tests if corePoolSize is greater than the maximumPoolSize |
292 |
> |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
293 |
|
public void testConstructor5() { |
294 |
< |
try{ |
295 |
< |
new ThreadPoolExecutor(2,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
296 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
294 |
> |
try { |
295 |
> |
new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
296 |
> |
shouldThrow(); |
297 |
|
} |
298 |
< |
catch (IllegalArgumentException i5){} |
298 |
> |
catch (IllegalArgumentException success){} |
299 |
|
} |
300 |
|
|
301 |
< |
//---- Tests if workQueue is set to null |
301 |
> |
/** Throws if workQueue is set to null */ |
302 |
|
public void testNullPointerException() { |
303 |
< |
try{ |
304 |
< |
new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null); |
305 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
303 |
> |
try { |
304 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null); |
305 |
> |
shouldThrow(); |
306 |
|
} |
307 |
< |
catch (NullPointerException n){} |
307 |
> |
catch (NullPointerException success){} |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
< |
//---- Tests if corePoolSize argument is less than zero |
312 |
> |
/** Throws if corePoolSize argument is less than zero */ |
313 |
|
public void testConstructor6() { |
314 |
< |
try{ |
315 |
< |
new ThreadPoolExecutor(-1,1,100L,TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread()); |
316 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
317 |
< |
} catch (IllegalArgumentException i6){} |
314 |
> |
try { |
315 |
> |
new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
316 |
> |
shouldThrow(); |
317 |
> |
} catch (IllegalArgumentException success){} |
318 |
|
} |
319 |
|
|
320 |
< |
//---- Tests if maximumPoolSize is less than zero |
320 |
> |
/** Throws if maximumPoolSize is less than zero */ |
321 |
|
public void testConstructor7() { |
322 |
< |
try{ |
323 |
< |
new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread()); |
324 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
322 |
> |
try { |
323 |
> |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
324 |
> |
shouldThrow(); |
325 |
|
} |
326 |
< |
catch (IllegalArgumentException i7){} |
326 |
> |
catch (IllegalArgumentException success){} |
327 |
|
} |
328 |
|
|
329 |
< |
//---- Tests if maximumPoolSize is equal to zero |
329 |
> |
/** Throws if maximumPoolSize is equal to zero */ |
330 |
|
public void testConstructor8() { |
331 |
< |
try{ |
332 |
< |
new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread()); |
333 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
331 |
> |
try { |
332 |
> |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
333 |
> |
shouldThrow(); |
334 |
|
} |
335 |
< |
catch (IllegalArgumentException i8){} |
335 |
> |
catch (IllegalArgumentException success){} |
336 |
|
} |
337 |
|
|
338 |
< |
//---- Tests if keepAliveTime is less than zero |
338 |
> |
/** Throws if keepAliveTime is less than zero */ |
339 |
|
public void testConstructor9() { |
340 |
< |
try{ |
341 |
< |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread()); |
342 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
340 |
> |
try { |
341 |
> |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
342 |
> |
shouldThrow(); |
343 |
|
} |
344 |
< |
catch (IllegalArgumentException i9){} |
344 |
> |
catch (IllegalArgumentException success){} |
345 |
|
} |
346 |
|
|
347 |
< |
//---- Tests if corePoolSize is greater than the maximumPoolSize |
347 |
> |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
348 |
|
public void testConstructor10() { |
349 |
< |
try{ |
350 |
< |
new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread()); |
351 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
349 |
> |
try { |
350 |
> |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory()); |
351 |
> |
shouldThrow(); |
352 |
|
} |
353 |
< |
catch (IllegalArgumentException i10){} |
353 |
> |
catch (IllegalArgumentException success){} |
354 |
|
} |
355 |
|
|
356 |
< |
//---- Tests if workQueue is set to null |
356 |
> |
/** Throws if workQueue is set to null */ |
357 |
|
public void testNullPointerException2() { |
358 |
< |
try{ |
359 |
< |
new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testThread()); |
360 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
358 |
> |
try { |
359 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory()); |
360 |
> |
shouldThrow(); |
361 |
|
} |
362 |
< |
catch (NullPointerException n2){} |
362 |
> |
catch (NullPointerException success){} |
363 |
|
} |
364 |
|
|
365 |
< |
//---- Tests if threadFactory is set to null |
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,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
370 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
369 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
370 |
> |
shouldThrow(); |
371 |
|
} |
372 |
< |
catch (NullPointerException n3){} |
372 |
> |
catch (NullPointerException success){} |
373 |
|
} |
374 |
|
|
375 |
|
|
376 |
< |
//---- Tests if corePoolSize argument is less than zero |
376 |
> |
/** Throws if corePoolSize argument is less than zero */ |
377 |
|
public void testConstructor11() { |
378 |
< |
try{ |
379 |
< |
new ThreadPoolExecutor(-1,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject()); |
380 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
378 |
> |
try { |
379 |
> |
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
380 |
> |
shouldThrow(); |
381 |
|
} |
382 |
< |
catch (IllegalArgumentException i11){} |
382 |
> |
catch (IllegalArgumentException success){} |
383 |
|
} |
384 |
|
|
385 |
< |
//---- Tests if maximumPoolSize is less than zero |
385 |
> |
/** Throws if maximumPoolSize is less than zero */ |
386 |
|
public void testConstructor12() { |
387 |
< |
try{ |
388 |
< |
new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject()); |
389 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
387 |
> |
try { |
388 |
> |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
389 |
> |
shouldThrow(); |
390 |
|
} |
391 |
< |
catch (IllegalArgumentException i12){} |
391 |
> |
catch (IllegalArgumentException success){} |
392 |
|
} |
393 |
|
|
394 |
< |
//---- Tests if maximumPoolSize is equal to zero |
394 |
> |
/** Throws if maximumPoolSize is equal to zero */ |
395 |
|
public void testConstructor13() { |
396 |
< |
try{ |
397 |
< |
new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject()); |
398 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
396 |
> |
try { |
397 |
> |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
398 |
> |
shouldThrow(); |
399 |
|
} |
400 |
< |
catch (IllegalArgumentException i13){} |
400 |
> |
catch (IllegalArgumentException success){} |
401 |
|
} |
402 |
|
|
403 |
< |
//---- Tests if keepAliveTime is less than zero |
403 |
> |
/** Throws if keepAliveTime is less than zero */ |
404 |
|
public void testConstructor14() { |
405 |
< |
try{ |
406 |
< |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject()); |
407 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
405 |
> |
try { |
406 |
> |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
407 |
> |
shouldThrow(); |
408 |
|
} |
409 |
< |
catch (IllegalArgumentException i14){} |
409 |
> |
catch (IllegalArgumentException success){} |
410 |
|
} |
411 |
|
|
412 |
< |
//---- Tests if corePoolSize is greater than the maximumPoolSize |
412 |
> |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
413 |
|
public void testConstructor15() { |
414 |
< |
try{ |
415 |
< |
new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testReject()); |
416 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
414 |
> |
try { |
415 |
> |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyREHandler()); |
416 |
> |
shouldThrow(); |
417 |
|
} |
418 |
< |
catch (IllegalArgumentException i15){} |
418 |
> |
catch (IllegalArgumentException success){} |
419 |
|
} |
420 |
|
|
421 |
< |
//---- Tests if workQueue is set to null |
421 |
> |
/** Throws if workQueue is set to null */ |
422 |
|
public void testNullPointerException4() { |
423 |
< |
try{ |
424 |
< |
new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testReject()); |
425 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
423 |
> |
try { |
424 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyREHandler()); |
425 |
> |
shouldThrow(); |
426 |
|
} |
427 |
< |
catch (NullPointerException n4){} |
427 |
> |
catch (NullPointerException success){} |
428 |
|
} |
429 |
|
|
430 |
< |
//---- Tests if handler is set to null |
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,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
435 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
434 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
435 |
> |
shouldThrow(); |
436 |
|
} |
437 |
< |
catch (NullPointerException n5){} |
437 |
> |
catch (NullPointerException success){} |
438 |
|
} |
439 |
|
|
440 |
|
|
441 |
< |
//---- Tests if corePoolSize argument is less than zero |
441 |
> |
/** Throws if corePoolSize argument is less than zero */ |
442 |
|
public void testConstructor16() { |
443 |
< |
try{ |
444 |
< |
new ThreadPoolExecutor(-1,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject()); |
445 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
443 |
> |
try { |
444 |
> |
new ThreadPoolExecutor(-1,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
445 |
> |
shouldThrow(); |
446 |
|
} |
447 |
< |
catch (IllegalArgumentException i16){} |
447 |
> |
catch (IllegalArgumentException success){} |
448 |
|
} |
449 |
|
|
450 |
< |
//---- Tests if maximumPoolSize is less than zero |
450 |
> |
/** Throws if maximumPoolSize is less than zero */ |
451 |
|
public void testConstructor17() { |
452 |
< |
try{ |
453 |
< |
new ThreadPoolExecutor(1,-1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject()); |
454 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
452 |
> |
try { |
453 |
> |
new ThreadPoolExecutor(1,-1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
454 |
> |
shouldThrow(); |
455 |
|
} |
456 |
< |
catch (IllegalArgumentException i17){} |
456 |
> |
catch (IllegalArgumentException success){} |
457 |
|
} |
458 |
|
|
459 |
< |
//---- Tests if maximumPoolSize is equal to zero |
459 |
> |
/** Throws if maximumPoolSize is equal to zero */ |
460 |
|
public void testConstructor18() { |
461 |
< |
try{ |
462 |
< |
new ThreadPoolExecutor(1,0,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject()); |
463 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
461 |
> |
try { |
462 |
> |
new ThreadPoolExecutor(1,0,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
463 |
> |
shouldThrow(); |
464 |
|
} |
465 |
< |
catch (IllegalArgumentException i18){} |
465 |
> |
catch (IllegalArgumentException success){} |
466 |
|
} |
467 |
|
|
468 |
< |
//---- Tests if keepAliveTime is less than zero |
468 |
> |
/** Throws if keepAliveTime is less than zero */ |
469 |
|
public void testConstructor19() { |
470 |
< |
try{ |
471 |
< |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject()); |
472 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
470 |
> |
try { |
471 |
> |
new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
472 |
> |
shouldThrow(); |
473 |
|
} |
474 |
< |
catch (IllegalArgumentException i19){} |
474 |
> |
catch (IllegalArgumentException success){} |
475 |
|
} |
476 |
|
|
477 |
< |
//---- Tests if corePoolSize is greater than the maximumPoolSize |
477 |
> |
/** Throws if corePoolSize is greater than the maximumPoolSize */ |
478 |
|
public void testConstructor20() { |
479 |
< |
try{ |
480 |
< |
new ThreadPoolExecutor(2,1,100L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new testThread(),new testReject()); |
481 |
< |
fail("ThreadPoolExecutor constructor should throw an IllegalArgumentException"); |
479 |
> |
try { |
480 |
> |
new ThreadPoolExecutor(2,1,SHORT_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),new MyREHandler()); |
481 |
> |
shouldThrow(); |
482 |
|
} |
483 |
< |
catch (IllegalArgumentException i20){} |
483 |
> |
catch (IllegalArgumentException success){} |
484 |
|
} |
485 |
|
|
486 |
< |
//---- Tests if workQueue is set to null |
486 |
> |
/** Throws if workQueue is set to null */ |
487 |
|
public void testNullPointerException6() { |
488 |
< |
try{ |
489 |
< |
new ThreadPoolExecutor(1,2,100L,TimeUnit.MILLISECONDS,null,new testThread(),new testReject()); |
490 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
488 |
> |
try { |
489 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,null,new MyThreadFactory(),new MyREHandler()); |
490 |
> |
shouldThrow(); |
491 |
|
} |
492 |
< |
catch (NullPointerException n6){} |
492 |
> |
catch (NullPointerException success){} |
493 |
|
} |
494 |
|
|
495 |
< |
//---- Tests if handler is set to null |
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,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new testThread(),r); |
500 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
499 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new MyThreadFactory(),r); |
500 |
> |
shouldThrow(); |
501 |
|
} |
502 |
< |
catch (NullPointerException n7){} |
502 |
> |
catch (NullPointerException success){} |
503 |
|
} |
504 |
|
|
505 |
< |
//---- Tests if ThradFactory is set top null |
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,100L,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new testReject()); |
510 |
< |
fail("ThreadPoolExecutor constructor should throw a NullPointerException"); |
509 |
> |
new ThreadPoolExecutor(1,2,SHORT_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new MyREHandler()); |
510 |
> |
shouldThrow(); |
511 |
|
} |
512 |
< |
catch (NullPointerException n8){} |
512 |
> |
catch (NullPointerException successdn8){} |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
|
/** |
517 |
< |
* Test to verify execute will throw RejectedExcutionException |
517 |
> |
* execute will throw RejectedExcutionException |
518 |
|
* ThreadPoolExecutor will throw one when more runnables are |
519 |
|
* executed then will fit in the Queue. |
520 |
|
*/ |
521 |
< |
public void testRejectedExecutedException(){ |
521 |
> |
public void testRejectedExecutionException() { |
522 |
|
ThreadPoolExecutor tpe = null; |
523 |
< |
try{ |
524 |
< |
tpe = new ThreadPoolExecutor(1,1,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(1)); |
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{ |
528 |
< |
tpe.execute(new Runnable(){ |
529 |
< |
public void run(){ |
543 |
< |
try{ |
544 |
< |
Thread.sleep(1000); |
545 |
< |
} catch(InterruptedException e){} |
546 |
< |
} |
547 |
< |
}); |
548 |
< |
fail("ThreadPoolExecutor - void execute(Runnable) should throw RejectedExecutionException"); |
527 |
> |
try { |
528 |
> |
tpe.execute(new NoOpRunnable()); |
529 |
> |
shouldThrow(); |
530 |
|
} catch(RejectedExecutionException success){} |
531 |
|
|
532 |
< |
|
532 |
> |
joinPool(tpe); |
533 |
|
} |
534 |
|
|
535 |
|
/** |
536 |
< |
* Test to verify setCorePoolSize will throw IllegalArgumentException |
536 |
> |
* setCorePoolSize will throw IllegalArgumentException |
537 |
|
* when given a negative |
538 |
|
*/ |
539 |
< |
public void testIllegalArgumentException1(){ |
539 |
> |
public void testCorePoolSizeIllegalArgumentException() { |
540 |
|
ThreadPoolExecutor tpe = null; |
541 |
< |
try{ |
542 |
< |
tpe = new ThreadPoolExecutor(1,2,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
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(); |
550 |
|
} |
551 |
+ |
joinPool(tpe); |
552 |
|
} |
553 |
|
|
554 |
|
|
555 |
|
/** |
556 |
< |
* Test to verify setMaximumPoolSize(int) will throw IllegalArgumentException |
556 |
> |
* setMaximumPoolSize(int) will throw IllegalArgumentException |
557 |
|
* if given a value less the it's actual core pool size |
558 |
|
*/ |
559 |
< |
public void testIllegalArgumentException2(){ |
559 |
> |
public void testMaximumPoolSizeIllegalArgumentException() { |
560 |
|
ThreadPoolExecutor tpe = null; |
561 |
< |
try{ |
562 |
< |
tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
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(); |
570 |
|
} |
571 |
+ |
joinPool(tpe); |
572 |
|
} |
573 |
|
|
574 |
|
/** |
575 |
< |
* Test to verify that setMaximumPoolSize will throw IllegalArgumentException |
575 |
> |
* setMaximumPoolSize will throw IllegalArgumentException |
576 |
|
* if given a negative number |
577 |
|
*/ |
578 |
< |
public void testIllegalArgumentException2SP(){ |
578 |
> |
public void testMaximumPoolSizeIllegalArgumentException2() { |
579 |
|
ThreadPoolExecutor tpe = null; |
580 |
< |
try{ |
581 |
< |
tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
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(); |
589 |
|
} |
590 |
+ |
joinPool(tpe); |
591 |
|
} |
592 |
|
|
593 |
|
|
594 |
|
/** |
595 |
< |
* Test to verify setKeepAliveTime will throw IllegalArgumentException |
595 |
> |
* setKeepAliveTime will throw IllegalArgumentException |
596 |
|
* when given a negative value |
597 |
|
*/ |
598 |
< |
public void testIllegalArgumentException3(){ |
598 |
> |
public void testKeepAliveTimeIllegalArgumentException() { |
599 |
|
ThreadPoolExecutor tpe = null; |
600 |
< |
try{ |
601 |
< |
tpe = new ThreadPoolExecutor(2,3,100,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
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(); |
610 |
|
} |
611 |
+ |
joinPool(tpe); |
612 |
|
} |
613 |
|
|
629 |
– |
|
630 |
– |
|
614 |
|
} |