1 /*** 2 * 3 * Copyright 2004 Protique Ltd 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.codehaus.activemq.management; 19 20 21 /*** 22 * @version $Revision: 1.2 $ 23 */ 24 public class TimeStatisticTest extends StatisticTestSupport { 25 26 public void testStatistic() throws Exception { 27 TimeStatisticImpl stat = new TimeStatisticImpl("myTimer", "millis", "myDescription"); 28 assertStatistic(stat, "myTimer", "millis", "myDescription"); 29 30 assertEquals(0, stat.getCount()); 31 32 stat.addTime(100); 33 assertEquals(1, stat.getCount()); 34 assertEquals(100, stat.getMinTime()); 35 assertEquals(100, stat.getMaxTime()); 36 37 stat.addTime(403); 38 assertEquals(2, stat.getCount()); 39 assertEquals(100, stat.getMinTime()); 40 assertEquals(403, stat.getMaxTime()); 41 42 stat.addTime(50); 43 assertEquals(3, stat.getCount()); 44 assertEquals(50, stat.getMinTime()); 45 assertEquals(403, stat.getMaxTime()); 46 47 48 assertEquals(553, stat.getTotalTime()); 49 50 Thread.sleep(500); 51 52 stat.addTime(10); 53 54 assertLastTimeNotStartTime(stat); 55 56 System.out.println("Stat is: " + stat); 57 58 stat.reset(); 59 60 assertEquals(0, stat.getCount()); 61 assertEquals(0, stat.getMinTime()); 62 assertEquals(0, stat.getMaxTime()); 63 assertEquals(0, stat.getTotalTime()); 64 65 stat.addTime(100); 66 assertEquals(1, stat.getCount()); 67 assertEquals(100, stat.getMinTime()); 68 assertEquals(100, stat.getMaxTime()); 69 assertEquals(100, stat.getTotalTime()); 70 71 } 72 }