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 com.reuters.msgtest.load.output.csv.ExcelCSVPrinter;
39 import java.io.IOException;
40 import java.io.Writer;
41 import java.util.Date;
42 import java.util.Iterator;
43
44
45 /***
46 * @author <a href="mailto:Kurman.Karabukaev@thoughtworks.com">Kurman</a>
47 *
48 */
49 public class LoadTestCSVWriter implements LoadTestOutput {
50 public void outputResults(LoadTestResults loadTestResults, Writer writer)
51 throws RvTestException {
52 ExcelCSVPrinter ecsvp = new ExcelCSVPrinter(writer);
53
54 try {
55 createHeader(loadTestResults.getLoadFixtureName(), ecsvp);
56
57 if (loadTestResults.size() < 1) {
58 ecsvp.writeln("No test results available");
59 } else {
60 ecsvp.writeln(new String[] {
61 "Number of runs :",
62 Integer.toString(loadTestResults.size())
63 });
64 ecsvp.writeln(new String[] {
65 "Test start time :",
66 new Date(loadTestResults.getTestStartTime()).toString()
67 });
68 ecsvp.writeln(new String[] {
69 "Last response received :",
70 new Date(loadTestResults.getLastResponseTime()).toString()
71 });
72 ecsvp.writeln(new String[] {
73 "Sum of all executions (mills.): ",
74 Long.toString((loadTestResults.getTotalExecutionTime()))
75 });
76 ecsvp.writeln(new String[] {
77 "Average execution time (mills.): ",
78 Long.toString(
79 (loadTestResults.getAverageExecutionTime()))
80 });
81 }
82
83 for (Iterator iter = loadTestResults.iterator(); iter.hasNext();) {
84 LoadTestResult loadTestResult = (LoadTestResult) iter.next();
85 ecsvp.writeln(new String[] {
86 Long.toString(loadTestResult.getSentTime()),
87 Long.toString(loadTestResult.getReceiveTime())
88 });
89 }
90
91 createFooter(ecsvp);
92 } catch (IOException e) {
93 throw new RvTestException("Could not write load test results", e);
94 } finally {
95 try {
96 ecsvp.close();
97 } catch (IOException e) {
98 }
99 }
100 }
101
102 private void createFooter(ExcelCSVPrinter ecsvp) throws IOException {
103 ecsvp.writeln();
104 ecsvp.writeln();
105 }
106
107 private void createHeader(String loadFixtureName, ExcelCSVPrinter ecsvp)
108 throws IOException {
109 ecsvp.writeln(new String[] { "Load Test Fixture : ", loadFixtureName });
110 ecsvp.writeln((new Date()).toString());
111 }
112 }