1 |
/* |
2 |
* Written by Martin Buchholz and Doug Lea with assistance from |
3 |
* members of JCP JSR-166 Expert Group and released to the public |
4 |
* domain, as explained at |
5 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
6 |
*/ |
7 |
|
8 |
import junit.framework.*; |
9 |
import java.util.concurrent.*; |
10 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
11 |
import java.util.*; |
12 |
|
13 |
public class ThreadPoolExecutor9Test extends JSR166TestCase { |
14 |
public static void main(String[] args) { |
15 |
junit.textui.TestRunner.run(suite()); |
16 |
} |
17 |
public static Test suite() { |
18 |
return new TestSuite(ThreadPoolExecutor9Test.class); |
19 |
} |
20 |
|
21 |
/** |
22 |
* Configuration changes that allow core pool size greater than |
23 |
* max pool size result in IllegalArgumentException. |
24 |
*/ |
25 |
public void testPoolSizeInvariants() { |
26 |
ThreadPoolExecutor p = |
27 |
new ThreadPoolExecutor(1, 1, |
28 |
LONG_DELAY_MS, MILLISECONDS, |
29 |
new ArrayBlockingQueue<Runnable>(10)); |
30 |
for (int s = 1; s < 5; s++) { |
31 |
p.setMaximumPoolSize(s); |
32 |
p.setCorePoolSize(s); |
33 |
try { |
34 |
p.setMaximumPoolSize(s - 1); |
35 |
shouldThrow(); |
36 |
} catch (IllegalArgumentException success) {} |
37 |
assertEquals(s, p.getCorePoolSize()); |
38 |
assertEquals(s, p.getMaximumPoolSize()); |
39 |
try { |
40 |
p.setCorePoolSize(s + 1); |
41 |
shouldThrow(); |
42 |
} catch (IllegalArgumentException success) {} |
43 |
assertEquals(s, p.getCorePoolSize()); |
44 |
assertEquals(s, p.getMaximumPoolSize()); |
45 |
} |
46 |
joinPool(p); |
47 |
} |
48 |
|
49 |
} |