Source Code Cross Referenced for ConnectionPoolTest.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » proxool » org.logicalcobwebs.proxool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.proxool;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:
011:        import java.sql.DriverManager;
012:        import java.sql.SQLException;
013:        import java.sql.Connection;
014:        import java.util.Properties;
015:
016:        /**
017:         * Test {@link ConnectionPool}
018:         *
019:         * @version $Revision: 1.3 $, $Date: 2006/01/18 14:40:06 $
020:         * @author billhorsman
021:         * @author $Author: billhorsman $ (current maintainer)
022:         * @since Proxool 0.8
023:         */
024:        public class ConnectionPoolTest extends AbstractProxoolTest {
025:
026:            private static final Log LOG = LogFactory
027:                    .getLog(ConnectionPoolTest.class);
028:
029:            public ConnectionPoolTest(String name) {
030:                super (name);
031:            }
032:
033:            /**
034:             * If we ask for more simultaneous connections then we have allowed we should gracefully
035:             * refuse them.
036:             */
037:            public void testMaximumConnectionCount() throws Exception {
038:
039:                String testName = "maximumConnectionCount";
040:                String alias = testName;
041:
042:                String url = TestHelper.buildProxoolUrl(alias,
043:                        TestConstants.HYPERSONIC_DRIVER,
044:                        TestConstants.HYPERSONIC_TEST_URL);
045:                Properties info = new Properties();
046:                info.setProperty(ProxoolConstants.USER_PROPERTY,
047:                        TestConstants.HYPERSONIC_USER);
048:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
049:                        TestConstants.HYPERSONIC_PASSWORD);
050:                info
051:                        .setProperty(
052:                                ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
053:                                "2");
054:                info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true");
055:                ProxoolFacade.registerConnectionPool(url, info);
056:
057:                DriverManager.getConnection(url);
058:                DriverManager.getConnection(url);
059:
060:                try {
061:                    DriverManager.getConnection(url);
062:                    fail("Didn't expect to get third connection");
063:                } catch (SQLException e) {
064:                    // Log message only so we don't get a worrying stack trace
065:                    LOG.debug("Ignoring expected exception: " + e.getMessage());
066:                }
067:
068:                assertEquals("activeConnectionCount", 2, ProxoolFacade
069:                        .getSnapshot(alias, true).getActiveConnectionCount());
070:
071:            }
072:
073:            /**
074:             * test what happens if maximum = minimum = 1
075:             */
076:            public void testMaximumEqualsMinimumConnectionCount()
077:                    throws Exception {
078:
079:                String testName = "maximumEqualsMinimumConnectionCount";
080:                String alias = testName;
081:
082:                String url = TestHelper.buildProxoolUrl(alias,
083:                        TestConstants.HYPERSONIC_DRIVER,
084:                        TestConstants.HYPERSONIC_TEST_URL);
085:                Properties info = new Properties();
086:                info.setProperty(ProxoolConstants.USER_PROPERTY,
087:                        TestConstants.HYPERSONIC_USER);
088:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
089:                        TestConstants.HYPERSONIC_PASSWORD);
090:                info
091:                        .setProperty(
092:                                ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
093:                                "1");
094:                info
095:                        .setProperty(
096:                                ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY,
097:                                "1");
098:                info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true");
099:                ProxoolFacade.registerConnectionPool(url, info);
100:
101:                // opening and closing a connection should have no effect
102:                Connection c1 = DriverManager.getConnection(url);
103:                c1.close();
104:
105:                // Leave this one open for a while
106:                Connection c2 = DriverManager.getConnection(url);
107:
108:                try {
109:                    Connection c3 = DriverManager.getConnection(url);
110:                    c3.close();
111:                    fail("Didn't expect to get third connection");
112:                } catch (SQLException e) {
113:                    // Log message only so we don't get a worrying stack trace
114:                    LOG.debug("Ignoring expected exception: " + e.getMessage());
115:                }
116:
117:                assertEquals("activeConnectionCount", 1, ProxoolFacade
118:                        .getSnapshot(alias, true).getActiveConnectionCount());
119:                c2.close();
120:
121:                // Just check it all still works
122:                DriverManager.getConnection(url).close();
123:
124:                assertEquals("activeConnectionCount", 0, ProxoolFacade
125:                        .getSnapshot(alias, true).getActiveConnectionCount());
126:
127:            }
128:
129:            /**
130:             * Checks whether shutdown is patient enough to wait for active connections
131:             */
132:            public void testShutdownPatience() throws ProxoolException,
133:                    SQLException {
134:
135:                String testName = "shutdownPatience";
136:                String alias = testName;
137:
138:                String url = TestHelper.buildProxoolUrl(alias,
139:                        TestConstants.HYPERSONIC_DRIVER,
140:                        TestConstants.HYPERSONIC_TEST_URL);
141:                Properties info = new Properties();
142:                info.setProperty(ProxoolConstants.USER_PROPERTY,
143:                        TestConstants.HYPERSONIC_USER);
144:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
145:                        TestConstants.HYPERSONIC_PASSWORD);
146:                info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true");
147:                ProxoolFacade.registerConnectionPool(url, info);
148:
149:                // Open a connection that will close in 5 seconds
150:                new Thread(new Closer(DriverManager.getConnection(url), 5000))
151:                        .start();
152:
153:                long startTime = System.currentTimeMillis();
154:                ProxoolFacade.removeConnectionPool(alias, 100000);
155:                long shutdownTime = System.currentTimeMillis() - startTime;
156:                assertTrue("shutdown took too long", shutdownTime < 50000);
157:                assertTrue("shutdown was too quick", shutdownTime > 2000);
158:            }
159:
160:            /**
161:             * Checks whether shutdown is impatient enough to shutdown even if
162:             * some connections are still active
163:             */
164:            public void testShutdownImpatience() throws ProxoolException,
165:                    SQLException {
166:
167:                String testName = "shutdownImpatience";
168:                String alias = testName;
169:
170:                String url = TestHelper.buildProxoolUrl(alias,
171:                        TestConstants.HYPERSONIC_DRIVER,
172:                        TestConstants.HYPERSONIC_TEST_URL);
173:                Properties info = new Properties();
174:                info.setProperty(ProxoolConstants.USER_PROPERTY,
175:                        TestConstants.HYPERSONIC_USER);
176:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
177:                        TestConstants.HYPERSONIC_PASSWORD);
178:                info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true");
179:                ProxoolFacade.registerConnectionPool(url, info);
180:
181:                // Open a connection that will close in 100 seconds
182:                new Thread(new Closer(DriverManager.getConnection(url), 100000))
183:                        .start();
184:
185:                long startTime = System.currentTimeMillis();
186:                ProxoolFacade.removeConnectionPool(alias, 3000);
187:                long shutdownTime = System.currentTimeMillis() - startTime;
188:                assertTrue("shutdown took too long", shutdownTime < 50000);
189:                assertTrue("shutdown was too quick", shutdownTime > 1000);
190:            }
191:
192:            class Closer implements  Runnable {
193:
194:                private Connection connection;
195:
196:                private long duration;
197:
198:                public Closer(Connection connection, long duration) {
199:                    this .connection = connection;
200:                    this .duration = duration;
201:                }
202:
203:                public void run() {
204:                    long startTime = System.currentTimeMillis();
205:                    try {
206:                        Thread.sleep(duration);
207:                    } catch (InterruptedException e) {
208:                        LOG.error("Awoken", e);
209:                    }
210:                    try {
211:                        connection.close();
212:                        LOG.debug("Connection closed after "
213:                                + (System.currentTimeMillis() - startTime)
214:                                + " milliseconds.");
215:                    } catch (SQLException e) {
216:                        LOG.error("Problem closing connection", e);
217:                    }
218:                }
219:
220:            }
221:
222:        }
223:
224:        /*
225:         Revision history:
226:         $Log: ConnectionPoolTest.java,v $
227:         Revision 1.3  2006/01/18 14:40:06  billhorsman
228:         Unbundled Jakarta's Commons Logging.
229:
230:         Revision 1.2  2004/06/02 21:05:19  billhorsman
231:         Don't log worrying stack traces for expected exceptions.
232:
233:         Revision 1.1  2003/10/26 16:10:46  billhorsman
234:         renamed to be more consistent
235:
236:         Revision 1.9  2003/09/11 23:14:57  billhorsman
237:         New test for when maximum-connection-count = 1 and minimum-connection-count = 1
238:
239:         Revision 1.8  2003/03/12 00:14:12  billhorsman
240:         change thresholds
241:
242:         Revision 1.7  2003/03/11 01:19:48  billhorsman
243:         new tests
244:
245:         Revision 1.6  2003/03/10 15:31:26  billhorsman
246:         fixes
247:
248:         Revision 1.5  2003/03/04 10:24:40  billhorsman
249:         removed try blocks around each test
250:
251:         Revision 1.4  2003/03/03 17:08:55  billhorsman
252:         all tests now extend AbstractProxoolTest
253:
254:         Revision 1.3  2003/03/03 11:12:04  billhorsman
255:         fixed licence
256:
257:         Revision 1.2  2003/03/01 15:27:24  billhorsman
258:         checkstyle
259:
260:         Revision 1.1  2003/02/27 18:01:47  billhorsman
261:         completely rethought the test structure. it's now
262:         more obvious. no new tests yet though.
263:
264:
265:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.