KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > pat > internal > TestResult


1 package org.objectweb.celtix.pat.internal;
2
3 public class TestResult {
4     public static final String JavaDoc AVG_UNIT = "(ms)";
5     private static final String JavaDoc THROUGHPUT_UNIT = "(invocations/sec)";
6     
7     private String JavaDoc name;
8     private TestCaseBase testCase;
9   
10     private double avgResponseTime;
11     private double throughput;
12   
13     public TestResult() {
14         this("Default Result");
15     }
16
17     public TestResult(String JavaDoc cname) {
18         this(cname, null);
19     }
20
21     public TestResult(String JavaDoc cname, TestCaseBase test) {
22         this.name = cname;
23         this.testCase = test;
24     }
25
26     public void compute(long startTime, long endTime, int numberOfInvocations) {
27         double numOfInvocations = (double)numberOfInvocations;
28         double duration = convertToSeconds(endTime - startTime);
29       
30         throughput = numOfInvocations / duration;
31         avgResponseTime = duration / numOfInvocations;
32     
33         System.out.println("Throughput: " + testCase.getOperationName() + " " + throughput + THROUGHPUT_UNIT);
34         System.out.println("AVG. response time: " + avgResponseTime * 1000 + AVG_UNIT);
35         System.out.println(numOfInvocations + " (invocations), running " + duration + " (sec) ");
36
37     }
38
39     private double convertToSeconds(double ms) {
40         return ms / 1000;
41     }
42
43     public String JavaDoc getName() {
44         return this.name;
45     }
46
47     public double getAvgResponseTime() {
48         return avgResponseTime;
49     }
50
51     public double getThroughput() {
52         return throughput;
53     }
54 }
55
Popular Tags