KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > management > RangeStatisticTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.management;
19
20 import org.apache.activemq.management.RangeStatisticImpl;
21
22 public class RangeStatisticTest extends StatisticTestSupport {
23     
24     private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
25             .getLog(RangeStatisticTest.class);
26
27     /**
28      * Use case for RangeStatisticImpl class.
29      * @throws Exception
30      */

31     public void testStatistic() throws Exception JavaDoc {
32         RangeStatisticImpl stat = new RangeStatisticImpl("myRange", "millis", "myDescription");
33         assertStatistic(stat, "myRange", "millis", "myDescription");
34
35         assertRangeStatistic(stat);
36     }
37
38     protected void assertRangeStatistic(RangeStatisticImpl stat) throws InterruptedException JavaDoc {
39         assertEquals(0, stat.getCurrent());
40         assertEquals(0, stat.getLowWaterMark());
41         assertEquals(0, stat.getHighWaterMark());
42
43         stat.setCurrent(100);
44         assertEquals(100, stat.getCurrent());
45         assertEquals(100, stat.getLowWaterMark());
46         assertEquals(100, stat.getHighWaterMark());
47
48         stat.setCurrent(50);
49         assertEquals(50, stat.getCurrent());
50         assertEquals(50, stat.getLowWaterMark());
51         assertEquals(100, stat.getHighWaterMark());
52
53         stat.setCurrent(200);
54         assertEquals(200, stat.getCurrent());
55         assertEquals(50, stat.getLowWaterMark());
56         assertEquals(200, stat.getHighWaterMark());
57
58         Thread.sleep(500);
59
60         stat.setCurrent(10);
61         assertEquals(10, stat.getCurrent());
62         assertEquals(10, stat.getLowWaterMark());
63         assertEquals(200, stat.getHighWaterMark());
64
65         assertLastTimeNotStartTime(stat);
66
67         log.info("Stat is: " + stat);
68
69         stat.reset();
70
71         assertEquals(0, stat.getCurrent());
72         assertEquals(0, stat.getLowWaterMark());
73         assertEquals(0, stat.getHighWaterMark());
74
75         stat.setCurrent(100);
76         assertEquals(100, stat.getCurrent());
77         assertEquals(100, stat.getLowWaterMark());
78         assertEquals(100, stat.getHighWaterMark());
79     }
80 }
81
Popular Tags