1 |
jsr166 |
1.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 static java.util.concurrent.TimeUnit.NANOSECONDS; |
12 |
|
|
import java.util.*; |
13 |
|
|
|
14 |
|
|
public class ThreadPoolExecutor9Test extends JSR166TestCase { |
15 |
|
|
public static void main(String[] args) { |
16 |
|
|
junit.textui.TestRunner.run(suite()); |
17 |
|
|
} |
18 |
|
|
public static Test suite() { |
19 |
|
|
return new TestSuite(ThreadPoolExecutor9Test.class); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
/** |
23 |
|
|
* Configuration changes that allow core pool size greater than |
24 |
|
|
* max pool size result in IllegalArgumentException. |
25 |
|
|
*/ |
26 |
|
|
public void testPoolSizeInvariants() { |
27 |
|
|
ThreadPoolExecutor p = |
28 |
|
|
new ThreadPoolExecutor(1, 1, |
29 |
|
|
LONG_DELAY_MS, MILLISECONDS, |
30 |
|
|
new ArrayBlockingQueue<Runnable>(10)); |
31 |
|
|
for (int s = 1; s < 5; s++) { |
32 |
|
|
p.setMaximumPoolSize(s); |
33 |
|
|
p.setCorePoolSize(s); |
34 |
|
|
try { |
35 |
|
|
p.setMaximumPoolSize(s - 1); |
36 |
|
|
shouldThrow(); |
37 |
|
|
} catch (IllegalArgumentException success) {} |
38 |
|
|
assertEquals(s, p.getCorePoolSize()); |
39 |
|
|
assertEquals(s, p.getMaximumPoolSize()); |
40 |
|
|
try { |
41 |
|
|
p.setCorePoolSize(s + 1); |
42 |
|
|
shouldThrow(); |
43 |
|
|
} catch (IllegalArgumentException success) {} |
44 |
|
|
assertEquals(s, p.getCorePoolSize()); |
45 |
|
|
assertEquals(s, p.getMaximumPoolSize()); |
46 |
|
|
} |
47 |
|
|
joinPool(p); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
} |