1 /*-----------------------------------------------
3 * Created on Apr 13, 2007
4 * LoadTestManagerThread.java
5 *-----------------------------------------------
7 package org
.spirit
.loadtest
;
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
) {
20 public LoadTestManager
getTestClient() {
24 private void loadSingleURL(String url
) {
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
) {
55 private void loadSequenceFile(final String script
) {
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
) {
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
);
81 loadSingleURL(getTestClient().getTestURL());