1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.performance.pool;
18
19 import java.io.InputStream;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Logger;
24 import org.apache.commons.dbcp.AbandonedConfig;
25 import org.apache.commons.dbcp.AbandonedObjectPool;
26 import org.apache.commons.math.stat.descriptive.SummaryStatistics;
27 import org.apache.commons.pool.impl.GenericObjectPool;
28 import junit.framework.Test;
29 import junit.framework.TestCase;
30 import junit.framework.TestSuite;
31
32 public class PoolSoakTest extends TestCase {
33
34
35 public PoolSoakTest(String name) {
36 super(name);
37 }
38
39
40 public static Test suite() {
41 return new TestSuite(PoolSoakTest.class);
42 }
43
44 protected PoolSoak poolSoak = null;
45
46 public void setUp() throws Exception {
47 poolSoak = new PoolSoak();
48 poolSoak.configure();
49 }
50
51 public void testGenericObjectPoolConfig() throws Exception {
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 poolSoak.getDigester().parse(getInputStream("config-pool.xml"));
67 poolSoak.init();
68 GenericObjectPool pool = poolSoak.getGenericObjectPool();
69 assertEquals(15, pool.getMaxActive());
70 assertEquals(15, pool.getMaxIdle());
71 assertEquals(10, pool.getMinIdle());
72 assertEquals(-1, pool.getMaxWait());
73 assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK,
74 pool.getWhenExhaustedAction());
75 assertEquals(false, pool.getTestOnBorrow());
76 assertEquals(false, pool.getTestOnReturn());
77 assertEquals(-1, pool.getTimeBetweenEvictionRunsMillis());
78 assertEquals(3, pool.getNumTestsPerEvictionRun());
79 assertEquals(-1, pool.getMinEvictableIdleTimeMillis());
80 assertEquals(false, pool.getTestWhileIdle());
81 }
82
83 public void testAbandonedObjectPoolConfig() throws Exception {
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 poolSoak.getDigester().parse(getInputStream("config-abandoned.xml"));
110 poolSoak.init();
111 AbandonedObjectPool pool = (AbandonedObjectPool) poolSoak.getGenericObjectPool();
112 assertEquals(15, pool.getMaxActive());
113 assertEquals(-1, pool.getMaxIdle());
114 assertEquals(0, pool.getMinIdle());
115 assertEquals(-1, pool.getMaxWait());
116 assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW,
117 pool.getWhenExhaustedAction());
118 assertEquals(true, pool.getTestOnBorrow());
119 assertEquals(false, pool.getTestOnReturn());
120 assertEquals(-1, pool.getTimeBetweenEvictionRunsMillis());
121 assertEquals(3, pool.getNumTestsPerEvictionRun());
122 assertEquals(-1, pool.getMinEvictableIdleTimeMillis());
123 assertEquals(true, pool.getTestWhileIdle());
124 }
125
126
127
128
129
130
131
132
133
134
135 protected InputStream getInputStream(String name) throws IOException {
136
137 return (this.getClass().getResourceAsStream
138 ("/org/apache/commons/performance/pool/" + name));
139 }
140
141 }