Source Code Cross Referenced for StatisticsTest.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » admin » 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.admin 
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.admin;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:        import org.logicalcobwebs.proxool.AbstractProxoolTest;
011:        import org.logicalcobwebs.proxool.ConnectionPoolDefinitionIF;
012:        import org.logicalcobwebs.proxool.ProxoolConstants;
013:        import org.logicalcobwebs.proxool.ProxoolFacade;
014:        import org.logicalcobwebs.proxool.ResultMonitor;
015:        import org.logicalcobwebs.proxool.TestConstants;
016:        import org.logicalcobwebs.proxool.TestHelper;
017:
018:        import java.sql.DriverManager;
019:        import java.text.DecimalFormat;
020:        import java.util.Properties;
021:
022:        /**
023:         * Test {@link StatisticsIF}
024:         *
025:         * @version $Revision: 1.22 $, $Date: 2006/01/18 14:40:06 $
026:         * @author Bill Horsman (bill@logicalcobwebs.co.uk)
027:         * @author $Author: billhorsman $ (current maintainer)
028:         * @since Proxool 0.7
029:         */
030:        public class StatisticsTest extends AbstractProxoolTest {
031:
032:            private static final Log LOG = LogFactory
033:                    .getLog(StatisticsTest.class);
034:
035:            private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat(
036:                    "0.00");
037:
038:            /**
039:             * @see junit.framework.TestCase#TestCase
040:             */
041:            public StatisticsTest(String s) {
042:                super (s);
043:            }
044:
045:            /**
046:             * Test whether the statistics we get back are roughly right.
047:             */
048:            public void testStatistics() throws Exception {
049:
050:                String testName = "statistics";
051:                String alias = testName;
052:
053:                String url = TestHelper.buildProxoolUrl(alias,
054:                        TestConstants.HYPERSONIC_DRIVER,
055:                        TestConstants.HYPERSONIC_TEST_URL);
056:                Properties info = new Properties();
057:                info.setProperty(ProxoolConstants.USER_PROPERTY,
058:                        TestConstants.HYPERSONIC_USER);
059:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
060:                        TestConstants.HYPERSONIC_PASSWORD);
061:                info.setProperty(ProxoolConstants.STATISTICS_PROPERTY,
062:                        "10s,15s");
063:                info
064:                        .setProperty(
065:                                ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY,
066:                                "1");
067:                info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true");
068:
069:                // We don't test whether anything is logged, but this line should make something appear
070:                info.setProperty(
071:                        ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY,
072:                        ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG);
073:
074:                // Register pool
075:                ProxoolFacade.registerConnectionPool(url, info);
076:
077:                // Skip past the first set because they will probably be for only part
078:                // of the 10s period.
079:                StatisticsResultMonitor srm = new StatisticsResultMonitor(
080:                        alias, "10s");
081:                assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult());
082:                srm.getStatistics();
083:
084:                DriverManager.getConnection(url).close();
085:
086:                srm = new StatisticsResultMonitor(alias, "10s") {
087:                    protected boolean check(StatisticsIF statistics) {
088:                        return (statistics.getServedCount() == 1);
089:                    }
090:                };
091:                assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult());
092:                StatisticsIF statistics = srm.getStatistics();
093:
094:                assertEquals("servedCount", 1L, statistics.getServedCount());
095:                assertEquals("servedPerSecond", 0.09, 0.11, statistics
096:                        .getServedPerSecond());
097:                assertEquals("refusedCount", 0L, statistics.getRefusedCount());
098:
099:            }
100:
101:            public void testOverhead() throws Exception {
102:                String testName = "overhead";
103:                String alias = testName;
104:                String url = TestHelper.buildProxoolUrl(alias,
105:                        TestConstants.HYPERSONIC_DRIVER,
106:                        TestConstants.HYPERSONIC_TEST_URL);
107:                Properties info = new Properties();
108:                info.setProperty(ProxoolConstants.USER_PROPERTY,
109:                        TestConstants.HYPERSONIC_USER);
110:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
111:                        TestConstants.HYPERSONIC_PASSWORD);
112:                info.setProperty(ProxoolConstants.STATISTICS_PROPERTY, "10s");
113:                info
114:                        .setProperty(
115:                                ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY,
116:                                "1");
117:
118:                // We don't test whether anything is logged, but this line should make something appear
119:                info.setProperty(
120:                        ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY,
121:                        ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG);
122:
123:                // Register pool
124:                ProxoolFacade.registerConnectionPool(url, info);
125:
126:                ConnectionPoolDefinitionIF cpd = ProxoolFacade
127:                        .getConnectionPoolDefinition(alias);
128:                Admin admin = new Admin(cpd);
129:
130:                final int loops = 100000;
131:                long start = System.currentTimeMillis();
132:                for (int i = 0; i < loops; i++) {
133:                    admin.connectionReturned(10);
134:                }
135:                double avg = (double) (System.currentTimeMillis() - start)
136:                        / (double) loops;
137:                LOG.info("Statistics take " + DECIMAL_FORMAT.format(avg * 1000)
138:                        + " microseconds");
139:
140:            }
141:
142:        }
143:
144:        /*
145:         Revision history:
146:         $Log: StatisticsTest.java,v $
147:         Revision 1.22  2006/01/18 14:40:06  billhorsman
148:         Unbundled Jakarta's Commons Logging.
149:
150:         Revision 1.21  2003/03/06 22:28:31  billhorsman
151:         another go at statistics threading (in tests)
152:
153:         Revision 1.20  2003/03/06 12:45:06  billhorsman
154:         switch on verbose logging
155:
156:         Revision 1.19  2003/03/06 10:37:41  billhorsman
157:         better timeout assertion
158:
159:         Revision 1.18  2003/03/04 10:58:44  billhorsman
160:         checkstyle
161:
162:         Revision 1.17  2003/03/04 10:24:41  billhorsman
163:         removed try blocks around each test
164:
165:         Revision 1.16  2003/03/03 17:09:09  billhorsman
166:         all tests now extend AbstractProxoolTest
167:
168:         Revision 1.15  2003/03/03 11:12:06  billhorsman
169:         fixed licence
170:
171:         Revision 1.14  2003/03/03 09:10:41  billhorsman
172:         removed debug
173:
174:         Revision 1.13  2003/03/02 01:16:37  billhorsman
175:         removed flakey average active time test
176:
177:         Revision 1.12  2003/03/01 18:25:53  billhorsman
178:         *** empty log message ***
179:
180:         Revision 1.11  2003/03/01 16:46:08  billhorsman
181:         debug
182:
183:         Revision 1.10  2003/03/01 16:14:32  billhorsman
184:         debug
185:
186:         Revision 1.9  2003/03/01 16:04:45  billhorsman
187:         fix
188:
189:         Revision 1.8  2003/03/01 15:27:25  billhorsman
190:         checkstyle
191:
192:         Revision 1.7  2003/02/28 12:36:33  billhorsman
193:         more robust waiting for statistics
194:
195:         Revision 1.6  2003/02/28 12:23:59  billhorsman
196:         more robust waiting for statistics
197:
198:         Revision 1.5  2003/02/27 18:01:49  billhorsman
199:         completely rethought the test structure. it's now
200:         more obvious. no new tests yet though.
201:
202:         Revision 1.4  2003/02/26 23:45:18  billhorsman
203:         add some sleep
204:
205:         Revision 1.3  2003/02/26 18:30:02  billhorsman
206:         test for stats overhead
207:
208:         Revision 1.2  2003/02/26 16:05:51  billhorsman
209:         widespread changes caused by refactoring the way we
210:         update and redefine pool definitions.
211:
212:         Revision 1.1  2003/02/20 00:33:15  billhorsman
213:         renamed monitor package -> admin
214:
215:         Revision 1.3  2003/02/19 23:36:50  billhorsman
216:         renamed monitor package to admin
217:
218:         Revision 1.2  2003/02/19 15:14:31  billhorsman
219:         fixed copyright (copy and paste error,
220:         not copyright change)
221:
222:         Revision 1.1  2003/02/07 17:28:36  billhorsman
223:         *** empty log message ***
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.