1 package org.apache.commons.jcs.utils.threadpool;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Properties;
24 import java.util.concurrent.ThreadPoolExecutor;
25
26 import junit.framework.TestCase;
27
28 import org.apache.commons.jcs.utils.props.PropertyLoader;
29
30
31
32
33
34
35
36 public class ThreadPoolManagerUnitTest
37 extends TestCase
38 {
39
40
41
42
43 public void testDefaultConfig()
44 {
45 Properties props = PropertyLoader.loadProperties( "thread_pool.properties" );
46 ThreadPoolManager.setProps( props );
47 ThreadPoolManager mgr = ThreadPoolManager.getInstance();
48 assertNotNull( mgr );
49
50 ThreadPoolExecutor pool = mgr.getPool( "test1" );
51 assertNotNull( pool );
52
53 int poolSize = pool.getPoolSize();
54 int expectedPoolSize = Integer.parseInt( props.getProperty( "thread_pool.test1.startUpSize" ) );
55 assertEquals( poolSize, expectedPoolSize );
56
57
58
59 int max = pool.getMaximumPoolSize();
60
61 int expected = Integer.parseInt( props.getProperty( "thread_pool.test1.maximumPoolSize" ) );
62 assertEquals(expected, max );
63 }
64
65
66
67
68 public void testDefaultConfigUndefinedPool()
69 {
70 Properties props = PropertyLoader.loadProperties( "thread_pool.properties" );
71 ThreadPoolManager.setProps( props );
72 ThreadPoolManager mgr = ThreadPoolManager.getInstance();
73 assertNotNull( mgr );
74
75 ThreadPoolExecutor pool = mgr.getPool( "doesnotexist" );
76 assertNotNull( pool );
77
78 int max = pool.getMaximumPoolSize();
79
80 int expected = Integer.parseInt( props.getProperty( "thread_pool.default.maximumPoolSize" ) );
81 assertEquals( expected, max );
82 }
83
84
85
86
87
88 public void testGetPoolNames()
89 {
90 ThreadPoolManager mgr = ThreadPoolManager.getInstance();
91 assertNotNull( mgr );
92
93 String poolName1 = "testGetPoolNames1";
94 mgr.getPool( poolName1 );
95
96 String poolName2 = "testGetPoolNames2";
97 mgr.getPool( poolName2 );
98
99 ArrayList<String> names = mgr.getPoolNames();
100 assertTrue( "Should have name in list.", names.contains( poolName1 ) );
101 assertTrue( "Should have name in list.", names.contains( poolName2 ) );
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 }