adding all of botlist, initial add
[botlist.git] / botlistprojects / botspider / spider / lib / java / spider_remote / src / org / spirit / loadtest / LoadTestManagerThread.java
blob670cf189b78e461a28ff4f17a2b471ca81835d2f
1 /*-----------------------------------------------
2 * Berlin Brown
3 * Created on Apr 13, 2007
4 * LoadTestManagerThread.java
5 *-----------------------------------------------
6 */
7 package org.spirit.loadtest;
9 /**
10 * Thread launched to send out HTTP requests and if enabled, write response and status
11 * information to file.
13 public class LoadTestManagerThread implements Runnable {
15 private LoadTestManager client;
17 public LoadTestManagerThread(LoadTestManager client) {
18 this.client = client;
20 public LoadTestManager getTestClient() {
21 return this.client;
24 private void loadSingleURL(String url) {
25 try {
26 long allStart = System.currentTimeMillis();
27 for (int i = 0; i < getTestClient().getLinesWrite(); i++) {
28 long tStart = System.currentTimeMillis();
29 System.out.println("attempting request to=" + url);
30 String [] responseTuple = LoadTestManager.connectURL(url, false);
31 long tEnd = System.currentTimeMillis();
32 long diff = tEnd - tStart;
33 System.out.println("single request time="
34 + diff + " ms -- from " + Thread.currentThread().getName());
35 LoadTestManager.log(diff, responseTuple, url);
36 // Move to next iteration.
37 this.getTestClient().incNumberOfRequests();
38 this.getTestClient().incTotalTime(diff);
39 Thread.sleep(getTestClient().getThreadSleepTime());
42 long allEnd = System.currentTimeMillis();
43 long perThreadDiff = allEnd - allStart;
44 System.out.println("All requests time=" + perThreadDiff + " ms");
46 // The following code buildRequestSection, clearRequest are needed after writing the HTML content
47 this.getTestClient().getHtmlOutput().buildRequestSection(perThreadDiff + " ms, requests=" + getTestClient().getLinesWrite());
48 this.getTestClient().getHtmlOutput().clearRequest();
50 } catch (Exception e) {
51 e.printStackTrace();
55 private void loadSequenceFile(final String script) {
56 try {
57 System.out.println("INFO: loading sequence script=" + script);
58 LoadTestSequenceParser parser = new LoadTestSequenceParser();
59 String realFilename = script.substring("script://".length());
60 parser.parse(realFilename);
61 parser.printSummary();
62 parser.handleSequence();
63 } catch (Exception e) {
64 e.printStackTrace();
68 public void run() {
69 if (this.getTestClient().isUseDataFile()) {
70 Object [] data = LoadTestManager.loadDataFile(this.getTestClient().getDataFile());
71 for (int i = 0; i < data.length; i++) {
72 String url = (String) data[i];
73 if (url.startsWith("script://")) {
74 loadSequenceFile(url);
75 } else {
76 loadSingleURL(url);
80 } else {
81 loadSingleURL(getTestClient().getTestURL());
85 // End of File