Source Code Cross Referenced for ConnectionResetterTest.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.Connection;
012:        import java.sql.DriverManager;
013:        import java.util.Properties;
014:
015:        /**
016:         * Test whether the {@link ConnectionResetter} works.
017:         *
018:         * @version $Revision: 1.16 $, $Date: 2006/01/18 14:40:06 $
019:         * @author Bill Horsman (bill@logicalcobwebs.co.uk)
020:         * @author $Author: billhorsman $ (current maintainer)
021:         * @since Proxool 0.5
022:         */
023:        public class ConnectionResetterTest extends AbstractProxoolTest {
024:
025:            private static final Log LOG = LogFactory
026:                    .getLog(ConnectionResetterTest.class);
027:
028:            /**
029:             * @see junit.framework.TestCase#TestCase
030:             */
031:            public ConnectionResetterTest(String s) {
032:                super (s);
033:            }
034:
035:            /**
036:             * Test whether autoCommit is correctly reset when a connection is
037:             * returned to the pool.
038:             */
039:            public void testAutoCommit() throws Exception {
040:
041:                String testName = "autoCommit";
042:                String alias = testName;
043:
044:                String url = TestHelper.buildProxoolUrl(alias,
045:                        TestConstants.HYPERSONIC_DRIVER,
046:                        TestConstants.HYPERSONIC_TEST_URL);
047:                Properties info = new Properties();
048:                info.setProperty(ProxoolConstants.USER_PROPERTY,
049:                        TestConstants.HYPERSONIC_USER);
050:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
051:                        TestConstants.HYPERSONIC_PASSWORD);
052:                ProxoolFacade.registerConnectionPool(url, info);
053:
054:                Connection c1 = DriverManager.getConnection(url);
055:
056:                Connection c2 = DriverManager.getConnection(url);
057:
058:                c1.setAutoCommit(false);
059:                c1.close();
060:
061:                c1 = DriverManager.getConnection(url);
062:                assertTrue("c1.getAutoCommit", c1.getAutoCommit());
063:
064:                c2.close();
065:                c1.close();
066:                assertEquals("connectionCount", 2, ProxoolFacade.getSnapshot(
067:                        alias).getConnectionCount());
068:
069:            }
070:
071:            /**
072:             * Test connectionCount when we deliberately introduce an exception during connection reset.
073:             */
074:            public void testFailedReset() throws Exception {
075:
076:                try {
077:                    // This is a bit of a hack to force an exception during reset
078:                    ConnectionResetter.setTriggerResetException(true);
079:
080:                    String testName = "failedReset";
081:                    String alias = testName;
082:
083:                    String url = TestHelper.buildProxoolUrl(alias,
084:                            TestConstants.HYPERSONIC_DRIVER,
085:                            TestConstants.HYPERSONIC_TEST_URL);
086:                    Properties info = new Properties();
087:                    info.setProperty(ProxoolConstants.USER_PROPERTY,
088:                            TestConstants.HYPERSONIC_USER);
089:                    info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
090:                            TestConstants.HYPERSONIC_PASSWORD);
091:                    ProxoolFacade.registerConnectionPool(url, info);
092:
093:                    Connection c1 = DriverManager.getConnection(url);
094:                    c1.setAutoCommit(false);
095:                    c1.close();
096:
097:                    assertEquals("connectionCount", 0, ProxoolFacade
098:                            .getSnapshot(alias).getConnectionCount());
099:                } finally {
100:                    // Back to normal
101:                    ConnectionResetter.setTriggerResetException(false);
102:                }
103:
104:            }
105:
106:            /**
107:             * Test whether autoCommit is correctly reset when a connection is
108:             * returned to the pool.
109:             */
110:            public void testReadOnly() throws Exception {
111:
112:                String testName = "readOnly";
113:                String alias = testName;
114:
115:                String url = TestHelper.buildProxoolUrl(alias,
116:                        TestConstants.HYPERSONIC_DRIVER,
117:                        TestConstants.HYPERSONIC_TEST_URL);
118:                Properties info = new Properties();
119:                info.setProperty(ProxoolConstants.USER_PROPERTY,
120:                        TestConstants.HYPERSONIC_USER);
121:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
122:                        TestConstants.HYPERSONIC_PASSWORD);
123:                info
124:                        .setProperty(
125:                                ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
126:                                "2");
127:                ProxoolFacade.registerConnectionPool(url, info);
128:
129:                Connection c1 = DriverManager.getConnection(url);
130:                ;
131:                Connection c2 = DriverManager.getConnection(url);
132:                ;
133:
134:                boolean originalReadOnly = c1.isReadOnly();
135:                c1.setReadOnly(true);
136:                c1.close();
137:
138:                c1 = DriverManager.getConnection(url);
139:                ;
140:                assertTrue("readOnly", c1.isReadOnly() == originalReadOnly);
141:
142:                c2.close();
143:                c1.close();
144:
145:            }
146:
147:        }
148:
149:        /*
150:         Revision history:
151:         $Log: ConnectionResetterTest.java,v $
152:         Revision 1.16  2006/01/18 14:40:06  billhorsman
153:         Unbundled Jakarta's Commons Logging.
154:
155:         Revision 1.15  2005/10/07 08:12:58  billhorsman
156:         Test deliberate exception durinng reset
157:
158:         Revision 1.14  2003/03/04 10:58:43  billhorsman
159:         checkstyle
160:
161:         Revision 1.13  2003/03/04 10:24:40  billhorsman
162:         removed try blocks around each test
163:
164:         Revision 1.12  2003/03/03 17:08:56  billhorsman
165:         all tests now extend AbstractProxoolTest
166:
167:         Revision 1.11  2003/03/03 11:12:04  billhorsman
168:         fixed licence
169:
170:         Revision 1.10  2003/02/27 18:01:47  billhorsman
171:         completely rethought the test structure. it's now
172:         more obvious. no new tests yet though.
173:
174:         Revision 1.9  2003/02/19 15:14:22  billhorsman
175:         fixed copyright (copy and paste error,
176:         not copyright change)
177:
178:         Revision 1.8  2003/02/06 17:41:02  billhorsman
179:         now uses imported logging
180:
181:         Revision 1.7  2002/12/16 17:05:38  billhorsman
182:         new test structure
183:
184:         Revision 1.6  2002/12/03 10:53:08  billhorsman
185:         checkstyle
186:
187:         Revision 1.5  2002/11/13 20:53:30  billhorsman
188:         new tests for autoCommit and readOnly
189:
190:         Revision 1.4  2002/11/12 20:24:12  billhorsman
191:         checkstyle
192:
193:         Revision 1.3  2002/11/12 20:18:26  billhorsman
194:         Made connection resetter a bit more friendly. Now, if it encounters any problems during
195:         reset then that connection is thrown away. This is going to cause you problems if you
196:         always close connections in an unstable state (e.g. with transactions open. But then
197:         again, it's better to know about that as soon as possible, right?
198:
199:         Revision 1.2  2002/11/09 16:01:21  billhorsman
200:         fixed CommandFilterIF implementation
201:
202:         Revision 1.1  2002/11/06 21:08:02  billhorsman
203:         new ConnectionResetter test
204:
205:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.