Source Code Cross Referenced for TestManual.java in  » Database-JDBC-Connection-Pool » Connection-Pool-DBCP » org » apache » commons » dbcp » 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 » Connection Pool DBCP » org.apache.commons.dbcp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.dbcp;
019:
020:        import java.io.PrintStream;
021:        import java.io.PrintWriter;
022:        import java.sql.Connection;
023:        import java.sql.DriverManager;
024:        import java.sql.SQLException;
025:
026:        import junit.framework.Test;
027:        import junit.framework.TestSuite;
028:
029:        import org.apache.commons.pool.ObjectPool;
030:        import org.apache.commons.pool.impl.GenericKeyedObjectPool;
031:        import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
032:        import org.apache.commons.pool.impl.GenericObjectPool;
033:
034:        /**
035:         * Tests for a "manually configured", {@link GenericObjectPool}
036:         * based {@link PoolingDriver}.
037:         * @author Rodney Waldhoff
038:         * @author Sean C. Sullivan
039:         * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
040:         */
041:        public class TestManual extends TestConnectionPool {
042:            public TestManual(String testName) {
043:                super (testName);
044:            }
045:
046:            public static Test suite() {
047:                return new TestSuite(TestManual.class);
048:            }
049:
050:            protected Connection getConnection() throws Exception {
051:                return DriverManager
052:                        .getConnection("jdbc:apache:commons:dbcp:test");
053:            }
054:
055:            private PoolingDriver driver = null;
056:
057:            public void setUp() throws Exception {
058:                super .setUp();
059:                GenericObjectPool pool = new GenericObjectPool(null,
060:                        getMaxActive(), GenericObjectPool.WHEN_EXHAUSTED_BLOCK,
061:                        getMaxWait(), 10, true, true, 10000L, 5, 5000L, true);
062:                DriverConnectionFactory cf = new DriverConnectionFactory(
063:                        new TesterDriver(), "jdbc:apache:commons:testdriver",
064:                        null);
065:                GenericKeyedObjectPoolFactory opf = new GenericKeyedObjectPoolFactory(
066:                        null, 10, GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK,
067:                        2000L, 10, true, true, 10000L, 5, 5000L, true);
068:                PoolableConnectionFactory pcf = new PoolableConnectionFactory(
069:                        cf, pool, opf, "SELECT COUNT(*) FROM DUAL", false, true);
070:                assertNotNull(pcf);
071:                driver = new PoolingDriver();
072:                driver.registerPool("test", pool);
073:                PoolingDriver.setAccessToUnderlyingConnectionAllowed(true);
074:                DriverManager.registerDriver(driver);
075:            }
076:
077:            public void tearDown() throws Exception {
078:                driver.closePool("test");
079:                DriverManager.deregisterDriver(driver);
080:            }
081:
082:            public void test1() {
083:                GenericObjectPool connectionPool = new GenericObjectPool(null);
084:                ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
085:                        "jdbc:some:connect:string", "username", "password");
086:                PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
087:                        connectionFactory, connectionPool, null, null, false,
088:                        true);
089:                PoolingDataSource dataSource = new PoolingDataSource(
090:                        connectionPool);
091:            }
092:
093:            public void test2() {
094:                GenericObjectPool connectionPool = new GenericObjectPool(null);
095:                ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
096:                        "jdbc:some:connect:string", "username", "password");
097:                PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
098:                        connectionFactory, connectionPool, null, null, false,
099:                        true);
100:                PoolingDriver driver = new PoolingDriver();
101:                driver.registerPool("example", connectionPool);
102:            }
103:
104:            /** @see http://issues.apache.org/bugzilla/show_bug.cgi?id=28912 */
105:            public void testReportedBug28912() throws Exception {
106:                Connection conn1 = getConnection();
107:                assertNotNull(conn1);
108:                conn1.close();
109:
110:                Connection conn2 = getConnection();
111:                assertNotNull(conn2);
112:
113:                try {
114:                    conn1.close();
115:                    fail("Expected SQLException");
116:                } catch (SQLException e) {
117:                }
118:            }
119:
120:            /** @see http://issues.apache.org/bugzilla/show_bug.cgi?id=12400 */
121:            public void testReportedBug12400() throws Exception {
122:                ObjectPool connectionPool = new GenericObjectPool(null, 70,
123:                        GenericObjectPool.WHEN_EXHAUSTED_BLOCK, 60000, 10);
124:                ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
125:                        "jdbc:apache:commons:testdriver", "username",
126:                        "password");
127:                PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
128:                        connectionFactory, connectionPool, null, null, false,
129:                        true);
130:                assertNotNull(poolableConnectionFactory);
131:                PoolingDriver driver = new PoolingDriver();
132:                driver.registerPool("neusoftim", connectionPool);
133:                Connection[] conn = new Connection[25];
134:                for (int i = 0; i < 25; i++) {
135:                    conn[i] = DriverManager
136:                            .getConnection("jdbc:apache:commons:dbcp:neusoftim");
137:                    for (int j = 0; j < i; j++) {
138:                        assertTrue(conn[j] != conn[i]);
139:                        assertTrue(!conn[j].equals(conn[i]));
140:                    }
141:                }
142:                for (int i = 0; i < 25; i++) {
143:                    conn[i].close();
144:                }
145:            }
146:
147:            public void testClosePool() throws Exception {
148:                Connection conn = DriverManager
149:                        .getConnection("jdbc:apache:commons:dbcp:test");
150:                assertNotNull(conn);
151:                conn.close();
152:
153:                PoolingDriver driver = (PoolingDriver) DriverManager
154:                        .getDriver("jdbc:apache:commons:dbcp:");
155:                driver.closePool("test");
156:
157:                try {
158:                    conn = DriverManager
159:                            .getConnection("jdbc:apache:commons:dbcp:test");
160:                    fail("expected SQLException");
161:                } catch (SQLException e) {
162:                    // OK
163:                }
164:            }
165:
166:            public void testInvalidateConnection() throws Exception {
167:                Connection conn = DriverManager
168:                        .getConnection("jdbc:apache:commons:dbcp:test");
169:                assertNotNull(conn);
170:
171:                ObjectPool pool = driver.getConnectionPool("test");
172:                assertEquals(1, pool.getNumActive());
173:                assertEquals(0, pool.getNumIdle());
174:
175:                PoolingDriver driver = (PoolingDriver) DriverManager
176:                        .getDriver("jdbc:apache:commons:dbcp:");
177:                driver.invalidateConnection(conn);
178:
179:                assertEquals(0, pool.getNumActive());
180:                assertEquals(0, pool.getNumIdle());
181:                assertTrue(conn.isClosed());
182:            }
183:
184:            public void testLogWriter() throws Exception {
185:                PrintStream ps = System.out;
186:                PrintWriter pw = new PrintWriter(System.err);
187:                SQLException ex;
188:
189:                DriverManager.setLogWriter(pw);
190:                ex = new SQLNestedException("A", new Exception("a"));
191:                ex.printStackTrace();
192:                ex.printStackTrace(ps);
193:                ex.printStackTrace(pw);
194:                ex = new SQLNestedException("B", null);
195:                ex.printStackTrace();
196:                ex.printStackTrace(ps);
197:                ex.printStackTrace(pw);
198:                ex = new SQLNestedException(null, new Exception("c"));
199:                ex.printStackTrace();
200:                ex.printStackTrace(ps);
201:                ex.printStackTrace(pw);
202:                ex = new SQLNestedException(null, null);
203:                ex.printStackTrace();
204:                ex.printStackTrace(ps);
205:                ex.printStackTrace(pw);
206:
207:                DriverManager.setLogWriter(null);
208:                ex = new SQLNestedException("A", new Exception("a"));
209:                ex.printStackTrace();
210:                ex.printStackTrace(ps);
211:                ex.printStackTrace(pw);
212:                ex = new SQLNestedException("B", null);
213:                ex.printStackTrace();
214:                ex.printStackTrace(ps);
215:                ex.printStackTrace(pw);
216:                ex = new SQLNestedException(null, new Exception("c"));
217:                ex.printStackTrace();
218:                ex.printStackTrace(ps);
219:                ex.printStackTrace(pw);
220:                ex = new SQLNestedException(null, null);
221:                ex.printStackTrace();
222:                ex.printStackTrace(ps);
223:                ex.printStackTrace(pw);
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.