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


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.pool;
017:
018:        import junit.framework.TestCase;
019:
020:        /**
021:         * Abstract {@link TestCase} for {@link ObjectPool} implementations.
022:         * @author Rodney Waldhoff
023:         * @version $Revision: 383290 $ $Date: 2006-03-05 02:00:15 -0500 (Sun, 05 Mar 2006) $
024:         */
025:        public abstract class TestObjectPool extends TestCase {
026:            public TestObjectPool(String testName) {
027:                super (testName);
028:            }
029:
030:            /** 
031:             * Create an {@link ObjectPool} instance
032:             * that can contain at least <i>mincapacity</i>
033:             * idle and active objects, or
034:             * throw {@link IllegalArgumentException}
035:             * if such a pool cannot be created.
036:             */
037:            protected abstract ObjectPool makeEmptyPool(int mincapacity);
038:
039:            /**
040:             * Return what we expect to be the n<sup>th</sup>
041:             * object (zero indexed) created by the _pool.
042:             */
043:            protected abstract Object getNthObject(int n);
044:
045:            /**
046:             * Is the implementations LIFO?
047:             * @return
048:             */
049:            protected abstract boolean isLifo();
050:
051:            /**
052:             * Is the implementationn FIFO?
053:             * @return
054:             */
055:            protected abstract boolean isFifo();
056:
057:            public void setUp() throws Exception {
058:            }
059:
060:            public void tearDown() throws Exception {
061:                _pool = null;
062:            }
063:
064:            public void testBaseBorrow() throws Exception {
065:                try {
066:                    _pool = makeEmptyPool(3);
067:                } catch (IllegalArgumentException e) {
068:                    return; // skip this test if unsupported
069:                }
070:                assertEquals(getNthObject(0), _pool.borrowObject());
071:                assertEquals(getNthObject(1), _pool.borrowObject());
072:                assertEquals(getNthObject(2), _pool.borrowObject());
073:            }
074:
075:            public void testBaseAddObject() throws Exception {
076:                try {
077:                    _pool = makeEmptyPool(3);
078:                } catch (IllegalArgumentException e) {
079:                    return; // skip this test if unsupported
080:                }
081:                try {
082:                    assertEquals(0, _pool.getNumIdle());
083:                    assertEquals(0, _pool.getNumActive());
084:                    _pool.addObject();
085:                    assertEquals(1, _pool.getNumIdle());
086:                    assertEquals(0, _pool.getNumActive());
087:                    Object obj = _pool.borrowObject();
088:                    assertEquals(getNthObject(0), obj);
089:                    assertEquals(0, _pool.getNumIdle());
090:                    assertEquals(1, _pool.getNumActive());
091:                    _pool.returnObject(obj);
092:                    assertEquals(1, _pool.getNumIdle());
093:                    assertEquals(0, _pool.getNumActive());
094:                } catch (UnsupportedOperationException e) {
095:                    return; // skip this test if one of those calls is unsupported
096:                }
097:            }
098:
099:            public void testBaseBorrowReturn() throws Exception {
100:                try {
101:                    _pool = makeEmptyPool(3);
102:                } catch (IllegalArgumentException e) {
103:                    return; // skip this test if unsupported
104:                }
105:                Object obj0 = _pool.borrowObject();
106:                assertEquals(getNthObject(0), obj0);
107:                Object obj1 = _pool.borrowObject();
108:                assertEquals(getNthObject(1), obj1);
109:                Object obj2 = _pool.borrowObject();
110:                assertEquals(getNthObject(2), obj2);
111:                _pool.returnObject(obj2);
112:                obj2 = _pool.borrowObject();
113:                assertEquals(getNthObject(2), obj2);
114:                _pool.returnObject(obj1);
115:                obj1 = _pool.borrowObject();
116:                assertEquals(getNthObject(1), obj1);
117:                _pool.returnObject(obj0);
118:                _pool.returnObject(obj2);
119:                obj2 = _pool.borrowObject();
120:                if (isLifo()) {
121:                    assertEquals(getNthObject(2), obj2);
122:                }
123:                if (isFifo()) {
124:                    assertEquals(getNthObject(0), obj2);
125:                }
126:
127:                obj0 = _pool.borrowObject();
128:                if (isLifo()) {
129:                    assertEquals(getNthObject(0), obj0);
130:                }
131:                if (isFifo()) {
132:                    assertEquals(getNthObject(2), obj0);
133:                }
134:            }
135:
136:            public void testBaseNumActiveNumIdle() throws Exception {
137:                try {
138:                    _pool = makeEmptyPool(3);
139:                } catch (IllegalArgumentException e) {
140:                    return; // skip this test if unsupported
141:                }
142:                assertEquals(0, _pool.getNumActive());
143:                assertEquals(0, _pool.getNumIdle());
144:                Object obj0 = _pool.borrowObject();
145:                assertEquals(1, _pool.getNumActive());
146:                assertEquals(0, _pool.getNumIdle());
147:                Object obj1 = _pool.borrowObject();
148:                assertEquals(2, _pool.getNumActive());
149:                assertEquals(0, _pool.getNumIdle());
150:                _pool.returnObject(obj1);
151:                assertEquals(1, _pool.getNumActive());
152:                assertEquals(1, _pool.getNumIdle());
153:                _pool.returnObject(obj0);
154:                assertEquals(0, _pool.getNumActive());
155:                assertEquals(2, _pool.getNumIdle());
156:            }
157:
158:            public void testBaseClear() throws Exception {
159:                try {
160:                    _pool = makeEmptyPool(3);
161:                } catch (IllegalArgumentException e) {
162:                    return; // skip this test if unsupported
163:                }
164:                assertEquals(0, _pool.getNumActive());
165:                assertEquals(0, _pool.getNumIdle());
166:                Object obj0 = _pool.borrowObject();
167:                Object obj1 = _pool.borrowObject();
168:                assertEquals(2, _pool.getNumActive());
169:                assertEquals(0, _pool.getNumIdle());
170:                _pool.returnObject(obj1);
171:                _pool.returnObject(obj0);
172:                assertEquals(0, _pool.getNumActive());
173:                assertEquals(2, _pool.getNumIdle());
174:                _pool.clear();
175:                assertEquals(0, _pool.getNumActive());
176:                assertEquals(0, _pool.getNumIdle());
177:                Object obj2 = _pool.borrowObject();
178:                assertEquals(getNthObject(2), obj2);
179:            }
180:
181:            public void testBaseInvalidateObject() throws Exception {
182:                try {
183:                    _pool = makeEmptyPool(3);
184:                } catch (IllegalArgumentException e) {
185:                    return; // skip this test if unsupported
186:                }
187:                assertEquals(0, _pool.getNumActive());
188:                assertEquals(0, _pool.getNumIdle());
189:                Object obj0 = _pool.borrowObject();
190:                Object obj1 = _pool.borrowObject();
191:                assertEquals(2, _pool.getNumActive());
192:                assertEquals(0, _pool.getNumIdle());
193:                _pool.invalidateObject(obj0);
194:                assertEquals(1, _pool.getNumActive());
195:                assertEquals(0, _pool.getNumIdle());
196:                _pool.invalidateObject(obj1);
197:                assertEquals(0, _pool.getNumActive());
198:                assertEquals(0, _pool.getNumIdle());
199:            }
200:
201:            public void testBaseClosePool() throws Exception {
202:                try {
203:                    _pool = makeEmptyPool(3);
204:                } catch (IllegalArgumentException e) {
205:                    return; // skip this test if unsupported
206:                }
207:                Object obj = _pool.borrowObject();
208:                _pool.returnObject(obj);
209:
210:                _pool.close();
211:                try {
212:                    _pool.borrowObject();
213:                    fail("Expected IllegalStateException");
214:                } catch (IllegalStateException e) {
215:                    // expected
216:                }
217:            }
218:
219:            public void testBaseCantCloseTwice() throws Exception {
220:                try {
221:                    _pool = makeEmptyPool(3);
222:                } catch (IllegalArgumentException e) {
223:                    return; // skip this test if unsupported
224:                }
225:                Object obj = _pool.borrowObject();
226:                _pool.returnObject(obj);
227:
228:                _pool.close();
229:                try {
230:                    _pool.close();
231:                    fail("Expected IllegalStateException");
232:                } catch (IllegalStateException e) {
233:                    // expected
234:                }
235:            }
236:
237:            private ObjectPool _pool = null;
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.