1 16 17 package org.springframework.util; 18 19 import java.util.Date ; 20 21 import junit.framework.TestCase; 22 23 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 assertEquals(upTime, System.currentTimeMillis() - begin, 300); 49 } 50 51 public void testGetLoadDate() { 52 Date now = new Date (); 53 ResponseTimeMonitorImpl impl = new ResponseTimeMonitorImpl(); 54 Date 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 |