KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > util > ResponseTimeMonitorTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.util;
18
19 import java.util.Date JavaDoc;
20
21 import junit.framework.TestCase;
22
23 /**
24  * @author Alef Arendsen
25  */

26 public class ResponseTimeMonitorTests extends TestCase {
27
28     public void testGetAccessCount() {
29         ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl();
30         assertEquals(impl.getAverageResponseTimeMillis(), 0);
31
32         impl.recordResponseTime(100);
33         impl.recordResponseTime(100);
34         impl.recordResponseTime(100);
35         
36         impl.recordResponseTime(300);
37         impl.recordResponseTime(200);
38         
39         assertEquals(impl.getAccessCount(), 5);
40     }
41
42     public void testGetUptime() {
43         long begin = System.currentTimeMillis();
44         ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl();
45         long upTime = impl.getUptimeMillis();
46         // Well, we can probably assert on the a delta of 300 ms otherwise
47
// the time is useless ;-)
48
assertEquals(upTime, System.currentTimeMillis() - begin, 300);
49     }
50
51     public void testGetLoadDate() {
52         Date JavaDoc now = new Date JavaDoc();
53         ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl();
54         Date JavaDoc d = impl.getLoadDate();
55         assertEquals(now.getTime(), d.getTime(), 300);
56     }
57
58     public void testGetAverageResponseTimeMillis() {
59         ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl();
60         assertEquals(impl.getAverageResponseTimeMillis(), 0);
61
62         impl.recordResponseTime(100);
63         impl.recordResponseTime(100);
64         impl.recordResponseTime(100);
65         assertEquals(impl.getAverageResponseTimeMillis(), 100);
66         
67         impl.recordResponseTime(300);
68         impl.recordResponseTime(200);
69         assertEquals(impl.getAverageResponseTimeMillis(), 160);
70     }
71
72     public void testGetBestResponseTimeMillis() {
73         ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl();
74         assertEquals(impl.getAverageResponseTimeMillis(), 0);
75
76         impl.recordResponseTime(100);
77         impl.recordResponseTime(100);
78         impl.recordResponseTime(100);
79         assertEquals(impl.getAverageResponseTimeMillis(), 100);
80
81         impl.recordResponseTime(300);
82         impl.recordResponseTime(200);
83         impl.recordResponseTime(60);
84         impl.recordResponseTime(500);
85         assertEquals(impl.getBestResponseTimeMillis(), 60);
86     }
87
88     public void testGetWorstResponseTimeMillis() {
89         ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl();
90         assertEquals(impl.getAverageResponseTimeMillis(), 0);
91
92         impl.recordResponseTime(100);
93         impl.recordResponseTime(100);
94         impl.recordResponseTime(100);
95         assertEquals(impl.getAverageResponseTimeMillis(), 100);
96
97         impl.recordResponseTime(300);
98         impl.recordResponseTime(200);
99         impl.recordResponseTime(60);
100         impl.recordResponseTime(500);
101         assertEquals(impl.getWorstResponseTimeMillis(), 500);
102     }
103
104 }
105
Popular Tags