1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package com.reuters.msgtest.load.output;
34
35 import com.reuters.msgtest.RvTestException;
36 import com.reuters.msgtest.load.LoadTestResult;
37 import com.reuters.msgtest.load.LoadTestResults;
38 import java.io.IOException;
39 import java.io.Writer;
40 import java.util.Date;
41 import java.util.Iterator;
42
43
44 /***
45 * @author <a href="mailto:Kurman.Karabukaev@thoughtworks.com">Kurman</a>
46 *
47 */
48 public class LoadTestWriter implements LoadTestOutput {
49 public void outputResults(LoadTestResults loadTestResults, Writer writer)
50 throws RvTestException {
51 try {
52 StringBuffer content = new StringBuffer();
53 createHeader(loadTestResults.getLoadFixtureName(), content);
54
55 if (loadTestResults.size() < 1) {
56 content.append("No test results available\n");
57 } else {
58 content.append("Number of runs :" + loadTestResults.size());
59 content.append("\n");
60 content.append("Test start time :" +
61 new Date(loadTestResults.getTestStartTime()));
62 content.append("\n");
63 content.append("Last response received :" +
64 new Date(loadTestResults.getLastResponseTime()));
65 content.append("\n");
66 content.append("Sum of all executions : " +
67 (loadTestResults.getTotalExecutionTime() / 1000) + " sec.");
68 content.append("\n");
69 content.append("Average execution time : " +
70 (loadTestResults.getAverageExecutionTime() / 1000) +
71 " sec.");
72 content.append("\n");
73 }
74
75 for (Iterator iter = loadTestResults.iterator(); iter.hasNext();) {
76 LoadTestResult loadTestResult = (LoadTestResult) iter.next();
77 content.append(loadTestResult.getSentTime() + ", " +
78 loadTestResult.getReceiveTime());
79 content.append("\n");
80 }
81
82 createFooter(content);
83 writer.write(content.toString());
84 } catch (IOException e) {
85 throw new RvTestException("Could not write load test results", e);
86 } finally {
87 try {
88 writer.close();
89 } catch (IOException e) {
90 }
91 }
92 }
93
94 private void createFooter(StringBuffer content) {
95 content.append("###########################\n");
96 }
97
98 private StringBuffer createHeader(String loadFixtureName,
99 StringBuffer content) {
100 content.append("###########################");
101 content.append("\n");
102 content.append("Load Test Fixture : " + loadFixtureName);
103 content.append("\n");
104 content.append(new Date());
105 content.append("\n");
106
107 return content;
108 }
109 }