Source Code Cross Referenced for PerfTestSessionBean.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » perf » ejb » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.perf.ejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.perf.ejb;
023:
024:        import java.io.IOException;
025:        import java.io.PrintWriter;
026:        import java.io.StringWriter;
027:        import java.text.NumberFormat;
028:        import javax.naming.InitialContext;
029:
030:        import org.jboss.test.perf.interfaces.PerfResult;
031:        import org.jboss.test.perf.interfaces.Probe;
032:        import org.jboss.test.perf.interfaces.ProbeHome;
033:        import org.jboss.test.perf.interfaces.ProbeLocal;
034:        import org.jboss.test.perf.interfaces.ProbeLocalHome;
035:        import org.jboss.test.util.Debug;
036:        import org.jboss.test.util.ejb.SessionSupport;
037:
038:        /** A session bean that tests intra-VM EJB call invocation overhead. The
039:         runProbeTests method accepts the number of iterations and returns a simple
040:         html report showing the output of each test run against the Probe session.
041:        
042:         @author Scott.Stark@jboss.org
043:         @version $Revision: 57211 $
044:         */
045:        public class PerfTestSessionBean extends SessionSupport {
046:            private static NumberFormat fmt = NumberFormat.getInstance();
047:            static {
048:                fmt.setMinimumFractionDigits(3);
049:                fmt.setMaximumFractionDigits(3);
050:            }
051:
052:            /** Run the unit tests using Probe and return a report as a string
053:             */
054:            public PerfResult runProbeTests(int iterationCount) {
055:                StringBuffer results = new StringBuffer("<h1>runProbeTests("
056:                        + iterationCount + ")</h1><pre>\n");
057:                int testCount = 0;
058:                int failureCount = 0;
059:
060:                PerfResult result = new PerfResult();
061:                try {
062:                    testCount++;
063:                    testProbeTimings(iterationCount, results);
064:                } catch (Exception e) {
065:                    failureCount++;
066:                    formatException(e, "testTimings", results);
067:                    result.error = e;
068:                }
069:                results.append('\n');
070:
071:                results.append("\nTotal tests: " + testCount);
072:                results.append("\nTotal failures: " + failureCount);
073:                results.append("\n</pre>");
074:                result.report = results.toString();
075:                return result;
076:            }
077:
078:            /** Run the unit tests using ProbeLocal and return a report as a string
079:             */
080:            public PerfResult runProbeLocalTests(int iterationCount) {
081:                StringBuffer results = new StringBuffer(
082:                        "<h1>runProbeLocalTests(" + iterationCount
083:                                + ")</h1><pre>\n");
084:                int testCount = 0;
085:                int failureCount = 0;
086:
087:                PerfResult result = new PerfResult();
088:                try {
089:                    testCount++;
090:                    testProbeLocalTimings(iterationCount, results);
091:                } catch (Exception e) {
092:                    failureCount++;
093:                    formatException(e, "testTimings", results);
094:                    result.error = e;
095:                }
096:                results.append('\n');
097:
098:                results.append("\nTotal tests: " + testCount);
099:                results.append("\nTotal failures: " + failureCount);
100:                results.append("\n</pre>");
101:                result.report = results.toString();
102:                return result;
103:            }
104:
105:            private void testProbeTimings(int iterationCount,
106:                    StringBuffer results) throws Exception {
107:                results.append("\n+++ testTimings()\n");
108:                Object obj = new InitialContext()
109:                        .lookup("java:comp/env/ejb/ProbeHome");
110:                Class homeClass = obj.getClass();
111:                ProbeHome home = null;
112:                results.append("ProbeHome Proxy class info:\n");
113:                Debug.displayClassInfo(homeClass, results);
114:                results.append("Local ProbeHome.class info:\n");
115:                Debug.displayClassInfo(ProbeHome.class, results);
116:                home = (ProbeHome) obj;
117:
118:                results.append("\nFound ProbeHome");
119:                Probe bean = home.create();
120:                results.append("\nCreated Probe");
121:                warmup(bean, results);
122:                noop(bean, iterationCount, results);
123:                ping(bean, iterationCount, results);
124:                echo(bean, iterationCount, results);
125:            }
126:
127:            private void testProbeLocalTimings(int iterationCount,
128:                    StringBuffer results) throws Exception {
129:                results.append("\n+++ testTimings()\n");
130:                Object obj = new InitialContext()
131:                        .lookup("java:comp/env/ejb/ProbeLocalHome");
132:                Class homeClass = obj.getClass();
133:                ProbeLocalHome home = null;
134:                results.append("ProbeLocalHome Proxy class info:\n");
135:                Debug.displayClassInfo(homeClass, results);
136:                results.append("Local ProbeLocalHome.class info:\n");
137:                Debug.displayClassInfo(ProbeLocalHome.class, results);
138:
139:                home = (ProbeLocalHome) obj;
140:                results.append("\nFound ProbeLocalHome");
141:                ProbeLocal bean = home.create();
142:                results.append("\nCreated ProbeLocal");
143:                warmup(bean, results);
144:                noop(bean, iterationCount, results);
145:                ping(bean, iterationCount, results);
146:                echo(bean, iterationCount, results);
147:            }
148:
149:            private void warmup(Probe bean, StringBuffer results)
150:                    throws Exception {
151:                bean.noop();
152:                bean.ping("Ping");
153:                bean.echo("Echo");
154:            }
155:
156:            private void warmup(ProbeLocal bean, StringBuffer results)
157:                    throws Exception {
158:                bean.noop();
159:                bean.ping("Ping");
160:                bean.echo("Echo");
161:            }
162:
163:            private void noop(Probe bean, int iterationCount,
164:                    StringBuffer results) throws Exception {
165:                results.append("\nStarting " + iterationCount
166:                        + " noop() invocations");
167:                long start = System.currentTimeMillis();
168:                for (int n = 0; n < iterationCount; n++)
169:                    bean.noop();
170:                long end = System.currentTimeMillis();
171:                long elapsed = end - start;
172:                float avgTime = elapsed;
173:                avgTime /= iterationCount;
174:                results.append("\n" + iterationCount + " noop() invocations = "
175:                        + elapsed + " ms, " + fmt.format(avgTime) + " ms/noop");
176:            }
177:
178:            private void noop(ProbeLocal bean, int iterationCount,
179:                    StringBuffer results) throws Exception {
180:                results.append("\nStarting " + iterationCount
181:                        + " noop() invocations");
182:                long start = System.currentTimeMillis();
183:                for (int n = 0; n < iterationCount; n++)
184:                    bean.noop();
185:                long end = System.currentTimeMillis();
186:                long elapsed = end - start;
187:                float avgTime = elapsed;
188:                avgTime /= iterationCount;
189:                results.append("\n" + iterationCount + " noop() invocations = "
190:                        + elapsed + " ms, " + fmt.format(avgTime) + " ms/noop");
191:            }
192:
193:            private void ping(Probe bean, int iterationCount,
194:                    StringBuffer results) throws Exception {
195:                results.append("\nStarting " + iterationCount
196:                        + " ping(PING) invocations");
197:                long start = System.currentTimeMillis();
198:                for (int n = 0; n < iterationCount; n++)
199:                    bean.ping("PING");
200:                long end = System.currentTimeMillis();
201:                long elapsed = end - start;
202:                float avgTime = elapsed;
203:                avgTime /= iterationCount;
204:                results.append("\n" + iterationCount + " ping() invocations = "
205:                        + elapsed + " ms, " + fmt.format(avgTime) + " ms/ping");
206:            }
207:
208:            private void ping(ProbeLocal bean, int iterationCount,
209:                    StringBuffer results) throws Exception {
210:                results.append("\nStarting " + iterationCount
211:                        + " ping(PING) invocations");
212:                long start = System.currentTimeMillis();
213:                for (int n = 0; n < iterationCount; n++)
214:                    bean.ping("PING");
215:                long end = System.currentTimeMillis();
216:                long elapsed = end - start;
217:                float avgTime = elapsed;
218:                avgTime /= iterationCount;
219:                results.append("\n" + iterationCount + " ping() invocations = "
220:                        + elapsed + " ms, " + fmt.format(avgTime) + " ms/ping");
221:            }
222:
223:            private void echo(Probe bean, int iterationCount,
224:                    StringBuffer results) throws Exception {
225:                results.append("\nStarting " + iterationCount
226:                        + " echo(ECHO) invocations");
227:                long start = System.currentTimeMillis();
228:                for (int n = 0; n < iterationCount; n++) {
229:                    String echo = bean.echo("ECHO");
230:                }
231:                long end = System.currentTimeMillis();
232:                long elapsed = end - start;
233:                float avgTime = elapsed;
234:                avgTime /= iterationCount;
235:                results.append("\n" + iterationCount + " echo() invocations = "
236:                        + elapsed + " ms, " + fmt.format(avgTime) + " ms/echo");
237:            }
238:
239:            private void echo(ProbeLocal bean, int iterationCount,
240:                    StringBuffer results) throws Exception {
241:                results.append("\nStarting " + iterationCount
242:                        + " echo(ECHO) invocations");
243:                long start = System.currentTimeMillis();
244:                for (int n = 0; n < iterationCount; n++) {
245:                    String echo = bean.echo("ECHO");
246:                }
247:                long end = System.currentTimeMillis();
248:                long elapsed = end - start;
249:                float avgTime = elapsed;
250:                avgTime /= iterationCount;
251:                results.append("\n" + iterationCount + " echo() invocations = "
252:                        + elapsed + " ms, " + fmt.format(avgTime) + " ms/echo");
253:            }
254:
255:            private void formatException(Throwable t, String testName,
256:                    StringBuffer results) {
257:                StringWriter sw = new StringWriter();
258:                PrintWriter pw = new PrintWriter(sw);
259:                t.printStackTrace(pw);
260:                results.append("\n" + testName + " failed:\n");
261:                results.append(sw.toString());
262:            }
263:
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.