Source Code Cross Referenced for StatisticsListenerTest.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.ProxoolConstants;
012:        import org.logicalcobwebs.proxool.ProxoolFacade;
013:        import org.logicalcobwebs.proxool.TestConstants;
014:        import org.logicalcobwebs.proxool.TestHelper;
015:
016:        import java.sql.DriverManager;
017:        import java.text.DateFormat;
018:        import java.text.SimpleDateFormat;
019:        import java.util.Date;
020:        import java.util.Properties;
021:
022:        /**
023:         * Test {@link StatisticsListenerIF}
024:         *
025:         * @version $Revision: 1.13 $, $Date: 2006/01/18 14:40:05 $
026:         * @author Bill Horsman (bill@logicalcobwebs.co.uk)
027:         * @author $Author: billhorsman $ (current maintainer)
028:         * @since Proxool 0.7
029:         */
030:        public class StatisticsListenerTest extends AbstractProxoolTest {
031:
032:            private static final Log LOG = LogFactory
033:                    .getLog(StatisticsListenerTest.class);
034:
035:            /**
036:             * HH:mm:ss
037:             */
038:            private static final DateFormat TIME_FORMAT = new SimpleDateFormat(
039:                    "mm:ss");
040:
041:            /**
042:             * @see junit.framework.TestCase#TestCase
043:             */
044:            public StatisticsListenerTest(String s) {
045:                super (s);
046:            }
047:
048:            /**
049:             * Can we listen to statistics
050:             */
051:            public void testListener() throws Exception {
052:
053:                String testName = "listener";
054:                String alias = testName;
055:                String url = TestHelper.buildProxoolUrl(alias,
056:                        TestConstants.HYPERSONIC_DRIVER,
057:                        TestConstants.HYPERSONIC_TEST_URL);
058:                Properties info = new Properties();
059:                info.setProperty(ProxoolConstants.USER_PROPERTY,
060:                        TestConstants.HYPERSONIC_USER);
061:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
062:                        TestConstants.HYPERSONIC_PASSWORD);
063:                info.setProperty(ProxoolConstants.STATISTICS_PROPERTY, "5s");
064:
065:                // We don't test whether anything is logged, but this line should make something appear
066:                info.setProperty(
067:                        ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY,
068:                        ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG);
069:
070:                // Register pool
071:                ProxoolFacade.registerConnectionPool(url, info);
072:
073:                // Add listener
074:                TestListener testListener = new TestListener();
075:                ProxoolFacade.addStatisticsListener(alias, testListener);
076:                Date lap0 = new Date();
077:
078:                // Wait for next statistics1 so we can guarantee that next set won't
079:                // be produced whilst we are building connection
080:                testListener.getNextStatistics();
081:                Date lap1 = new Date();
082:
083:                DriverManager.getConnection(url).close();
084:                Date lap2 = new Date();
085:                StatisticsIF statistics1 = testListener.getNextStatistics();
086:                Date lap3 = new Date();
087:                StatisticsIF statistics2 = testListener.getNextStatistics();
088:                Date lap4 = new Date();
089:
090:                StringBuffer detail = new StringBuffer();
091:                detail.append("lap0:");
092:                detail.append(TIME_FORMAT.format(lap0));
093:                detail.append(", lap1:");
094:                detail.append(TIME_FORMAT.format(lap1));
095:                detail.append(", lap2:");
096:                detail.append(TIME_FORMAT.format(lap2));
097:                detail.append(", lap3:");
098:                detail.append(TIME_FORMAT.format(lap3));
099:                detail.append("(");
100:                detail.append(statistics1.getServedCount());
101:                detail.append("), lap4:");
102:                detail.append(TIME_FORMAT.format(lap4));
103:                detail.append("(");
104:                detail.append(statistics2.getServedCount());
105:                detail.append(")");
106:                assertEquals("servedCount - " + detail, 1L, statistics1
107:                        .getServedCount());
108:
109:            }
110:
111:            class TestListener implements  StatisticsListenerIF {
112:
113:                private StatisticsIF statistics;
114:
115:                private boolean somethingHappened;
116:
117:                public void statistics(String alias, StatisticsIF statistics) {
118:                    this .statistics = statistics;
119:                    somethingHappened = true;
120:                }
121:
122:                void reset() {
123:                    statistics = null;
124:                    somethingHappened = false;
125:                }
126:
127:                public StatisticsIF getStatistics() {
128:                    return statistics;
129:                }
130:
131:                void waitForSomethingToHappen() {
132:
133:                    long start = System.currentTimeMillis();
134:                    while (!somethingHappened) {
135:                        try {
136:                            Thread.sleep(500);
137:                        } catch (InterruptedException e) {
138:                            LOG.error("Awoken", e);
139:                        }
140:                        if (System.currentTimeMillis() - start > 30000) {
141:                            fail("Timeout waiting for something to happen");
142:                        }
143:                    }
144:
145:                }
146:
147:                StatisticsIF getNextStatistics() {
148:                    somethingHappened = false;
149:                    waitForSomethingToHappen();
150:                    return statistics;
151:                }
152:
153:            }
154:        }
155:
156:        /*
157:         Revision history:
158:         $Log: StatisticsListenerTest.java,v $
159:         Revision 1.13  2006/01/18 14:40:05  billhorsman
160:         Unbundled Jakarta's Commons Logging.
161:
162:         Revision 1.12  2003/09/05 16:27:27  billhorsman
163:         Better debug output.
164:
165:         Revision 1.11  2003/03/04 10:58:44  billhorsman
166:         checkstyle
167:
168:         Revision 1.10  2003/03/04 10:24:40  billhorsman
169:         removed try blocks around each test
170:
171:         Revision 1.9  2003/03/03 17:09:08  billhorsman
172:         all tests now extend AbstractProxoolTest
173:
174:         Revision 1.8  2003/03/03 11:12:05  billhorsman
175:         fixed licence
176:
177:         Revision 1.7  2003/03/01 15:49:33  billhorsman
178:         fix
179:
180:         Revision 1.6  2003/03/01 15:38:38  billhorsman
181:         better assert msg
182:
183:         Revision 1.5  2003/03/01 15:27:25  billhorsman
184:         checkstyle
185:
186:         Revision 1.4  2003/02/27 18:01:48  billhorsman
187:         completely rethought the test structure. it's now
188:         more obvious. no new tests yet though.
189:
190:         Revision 1.3  2003/02/27 09:45:33  billhorsman
191:         sleep a little
192:
193:         Revision 1.2  2003/02/26 16:05:51  billhorsman
194:         widespread changes caused by refactoring the way we
195:         update and redefine pool definitions.
196:
197:         Revision 1.1  2003/02/20 00:33:15  billhorsman
198:         renamed monitor package -> admin
199:
200:         Revision 1.5  2003/02/19 23:36:50  billhorsman
201:         renamed monitor package to admin
202:
203:         Revision 1.4  2003/02/19 15:14:30  billhorsman
204:         fixed copyright (copy and paste error,
205:         not copyright change)
206:
207:         Revision 1.3  2003/02/07 17:28:23  billhorsman
208:         checkstyle and doc
209:
210:         Revision 1.2  2003/02/07 15:11:33  billhorsman
211:         checkstyle
212:
213:         Revision 1.1  2003/02/07 15:10:37  billhorsman
214:         new admin tests
215:
216:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.