RangeStatisticTest xref

    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.1 $
    23   */
    24  public class RangeStatisticTest extends StatisticTestSupport {
    25
    26      public void testStatistic() throws Exception {
    27          RangeStatisticImpl stat = new RangeStatisticImpl("myRange", "millis", "myDescription");
    28          assertStatistic(stat, "myRange", "millis", "myDescription");
    29
    30          assertRangeStatistic(stat);
    31      }
    32
    33      protected void assertRangeStatistic(RangeStatisticImpl stat) throws InterruptedException {
    34          assertEquals(0, stat.getCurrent());
    35          assertEquals(0, stat.getLowWaterMark());
    36          assertEquals(0, stat.getHighWaterMark());
    37
    38          stat.setCurrent(100);
    39          assertEquals(100, stat.getCurrent());
    40          assertEquals(100, stat.getLowWaterMark());
    41          assertEquals(100, stat.getHighWaterMark());
    42
    43          stat.setCurrent(50);
    44          assertEquals(50, stat.getCurrent());
    45          assertEquals(50, stat.getLowWaterMark());
    46          assertEquals(100, stat.getHighWaterMark());
    47
    48          stat.setCurrent(200);
    49          assertEquals(200, stat.getCurrent());
    50          assertEquals(50, stat.getLowWaterMark());
    51          assertEquals(200, stat.getHighWaterMark());
    52
    53          Thread.sleep(500);
    54
    55          stat.setCurrent(10);
    56          assertEquals(10, stat.getCurrent());
    57          assertEquals(10, stat.getLowWaterMark());
    58          assertEquals(200, stat.getHighWaterMark());
    59
    60          assertLastTimeNotStartTime(stat);
    61
    62          System.out.println("Stat is: " + stat);
    63
    64          stat.reset();
    65
    66          assertEquals(0, stat.getCurrent());
    67          assertEquals(0, stat.getLowWaterMark());
    68          assertEquals(0, stat.getHighWaterMark());
    69
    70          stat.setCurrent(100);
    71          assertEquals(100, stat.getCurrent());
    72          assertEquals(100, stat.getLowWaterMark());
    73          assertEquals(100, stat.getHighWaterMark());
    74      }
    75  }