Source Code Cross Referenced for ThreadedBatchTester.java in  » GIS » GeoServer » org » vfny » geoserver » 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 » GIS » GeoServer » org.vfny.geoserver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        /*
006:         * Created on Feb 16, 2004
007:         *
008:         * To change the template for this generated file go to
009:         * Window - Preferences - Java - Code Generation - Code and Comments
010:         */
011:        package org.vfny.geoserver;
012:
013:        import java.io.BufferedReader;
014:        import java.io.File;
015:        import java.io.FileOutputStream;
016:        import java.io.FileReader;
017:        import java.io.IOException;
018:        import java.io.PrintStream;
019:        import java.net.HttpURLConnection;
020:        import java.net.URL;
021:        import java.util.Date;
022:
023:        /**
024:         * ThreadedBatchTester purpose.
025:         * 
026:         * <p>
027:         * Description of ThreadedBatchTester ...
028:         * </p>
029:         *
030:         * @author dzwiers, Refractions Research, Inc.
031:         * @author $Author: cholmesny $ (last modification)
032:         * @version $Id: ThreadedBatchTester.java 6326 2007-03-15 18:36:40Z jdeolive $
033:         */
034:        public class ThreadedBatchTester extends Thread {
035:            private static int runs = 100;
036:            private static URL url;
037:            private static boolean isPost;
038:            private static String req = "";
039:            private static File log;
040:            private static long start;
041:            private static int finished = 0;
042:            private static int wait = 2;
043:            private static String postUrl = "http://localhost:8080/geoserver/wfs";
044:
045:            public ThreadedBatchTester() {
046:            }
047:
048:            public void run() {
049:                try {
050:                    start = new Date().getTime();
051:
052:                    Thread[] threads = new Thread[runs];
053:
054:                    if (isPost) {
055:                        url = new URL(postUrl);
056:                        for (int i = 0; i < runs; i++)
057:                            threads[i] = new TestPostThread(url, req);
058:                    } else {
059:                        if (url == null) {
060:                            url = new URL(req);
061:                        }
062:
063:                        for (int i = 0; i < runs; i++)
064:                            threads[i] = new TestGetThread(url);
065:                    }
066:
067:                    for (int i = 0; i < runs; i++) {
068:                        threads[i].start();
069:                        //If the wait time is not set at a few milliseconds then 
070:                        //we get these BindExceptions, or ConnectExceptions.
071:                        //I'm not sure if it's really a problem with the servlet
072:                        //container or this client code...  Seems like there should
073:                        //be someway to tell the threads to maybe try to wait for a
074:                        //bit?
075:                        sleep(wait);
076:                    }
077:
078:                    while (finished < runs) {
079:                        sleep(1);
080:                    }
081:
082:                    PrintStream os = System.out;
083:
084:                    if ((log != null) && (log.getAbsoluteFile() != null)) {
085:                        log = log.getAbsoluteFile();
086:                        os = new PrintStream(new FileOutputStream(log));
087:                    }
088:
089:                    generateOutput(threads, os);
090:                } catch (Exception e) {
091:                    e.printStackTrace();
092:                    usage();
093:                }
094:            }
095:
096:            public static synchronized void threadDone() {
097:                finished++;
098:            }
099:
100:            public static void main(String[] args) {
101:                try {
102:                    loadArgs(args);
103:
104:                    ThreadedBatchTester tester = new ThreadedBatchTester();
105:                    tester.run();
106:                } catch (Exception e) {
107:                    e.printStackTrace();
108:                    usage();
109:                }
110:            }
111:
112:            private static void generateOutput(Thread[] threads, PrintStream os) {
113:                int good = 0;
114:
115:                for (int i = 0; i < runs; i++) {
116:                    switch (((TestGetThread) threads[i]).getResult()) {
117:                    case HttpURLConnection.HTTP_OK:
118:                        good++;
119:
120:                    default:
121:                    }
122:                }
123:
124:                os.println(good + "/" + runs + " Tests 'OK' ("
125:                        + ((good * 1.0) / (runs * 1.0)) + ")\n");
126:
127:                for (int i = 0; i < runs; i++) {
128:                    TestGetThread tpt = (TestGetThread) threads[i];
129:
130:                    int result = tpt.getResult();
131:                    if (tpt.getTime2() == null) {
132:                        os.print(result + " Could not connect\n");
133:                    } else if (tpt.getTime3() == null) {
134:                        os.print(result + " Could not complete read\n");
135:                    } else {
136:                        os.print(tpt.getResult() + ", ");
137:                        os.print(tpt.getTime1().getTime() + ", ");
138:
139:                        if (tpt.getTime2() != null) {
140:                            os.print(tpt.getTime2().getTime() + ", ");
141:                        }
142:
143:                        if (tpt.getTime3() != null) {
144:                            os.print(tpt.getTime3().getTime() + ", ");
145:                            double time = (tpt.getTime3().getTime() - tpt
146:                                    .getTime1().getTime()) / 1000.0;
147:                            os.print("time (s): " + time + "\n");
148:                        } else {
149:                            os.print("null\n");
150:                        }
151:                    }
152:                }
153:
154:                long end = new Date().getTime();
155:                os.println(good + "/" + runs + " Tests 'OK' ("
156:                        + ((good * 1.0) / (runs * 1.0)) + ")\n");
157:
158:                os.println("Total time (s): " + ((end - start) / 1000.0)
159:                        + " (start: " + start + ", end: " + end + ")");
160:            }
161:
162:            private static void loadArgs(String[] args) throws IOException {
163:                if (args.length == 0) {
164:                    return;
165:                }
166:
167:                int i = 0;
168:
169:                //Is this weird nested structure necessary? ch
170:                while (i < args.length) {
171:                    String key = args[i++];
172:
173:                    if ("-n".equals(key) && (i < args.length)) {
174:                        String val = args[i++];
175:                        runs = Integer.parseInt(val);
176:                    } else {
177:                        if ("-r".equals(key) && (i < args.length)) {
178:                            String val = args[i++];
179:                            File f = new File(val);
180:                            FileReader fr = new FileReader(f);
181:                            BufferedReader br = new BufferedReader(fr);
182:                            String t = "";
183:                            //does this ready loop work here?  It doesn't for 
184:                            //the threads... ch
185:                            while (br.ready())
186:                                t += br.readLine();
187:
188:                            req = t;
189:                            //this also will get a null for the URL, need to 
190:                            //specify that somewhere... ch
191:                        } else {
192:                            if ("-u".equals(key) && (i < args.length)) {
193:                                String val = args[i++];
194:                                url = new URL(val);
195:                            } else {
196:                                if ("-l".equals(key) && (i < args.length)) {
197:                                    String val = args[i++];
198:                                    log = new File(val);
199:                                } else {
200:                                    if ("-p".equals(key)) {
201:                                        isPost = true;
202:                                    } else { // usage
203:                                        if ("-w".equals(key) && i < args.length) {
204:                                            wait = Integer.parseInt(args[i++]);
205:                                        } else {
206:                                            usage();
207:                                        }
208:                                    }
209:                                }
210:                            }
211:                        }
212:                    }
213:                }
214:            }
215:
216:            static void usage() {
217:                System.out.println("USAGE:\n");
218:                System.out
219:                        .println("ThreadedBatchTester [-p][-n][-w] [-r | -u]");
220:                System.out
221:                        .println("-n\t Optional\t Number of duplicate requests to create and run.");
222:                System.out
223:                        .println("-p\t Optional\t Number of duplicate requests to create and run.");
224:                System.out
225:                        .println("-r\t Optional\t Mutually Exclusive with -u\t The file containing the request to execute.");
226:                System.out
227:                        .println("-u\t Optional\t Mutually Exclusive with -r\t The URL to execute.");
228:                System.out.println("-l\t Optional\t The Log file.");
229:                System.out
230:                        .println("-w\t Optional\t Amount of time to wait between dispatching requests (in ms)");
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.