001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.test;
019
020import org.apache.hadoop.hbase.metrics.BaseSource;
021
022/** Interface of a class to make assertions about metrics values. */
023public interface MetricsAssertHelper {
024
025  /**
026   * Init helper. This method will make sure that the metrics system is set up for tests.
027   */
028  void init();
029
030  /**
031   * Assert that a tag exists and has a given value.
032   * @param name     The name of the tag.
033   * @param expected The expected value
034   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
035   *                 counters.
036   */
037  void assertTag(String name, String expected, BaseSource source);
038
039  /**
040   * Assert that a gauge exists and that it's value is equal to the expected value.
041   * @param name     The name of the gauge
042   * @param expected The expected value of the gauge.
043   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
044   *                 counters.
045   */
046  void assertGauge(String name, long expected, BaseSource source);
047
048  /**
049   * Assert that a gauge exists and it's value is greater than a given value
050   * @param name     The name of the gauge
051   * @param expected Value that the gauge is expected to be greater than
052   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
053   *                 counters.
054   */
055  void assertGaugeGt(String name, long expected, BaseSource source);
056
057  /**
058   * Assert that a gauge exists and it's value is less than a given value
059   * @param name     The name of the gauge
060   * @param expected Value that the gauge is expected to be less than
061   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
062   *                 counters.
063   */
064  void assertGaugeLt(String name, long expected, BaseSource source);
065
066  /**
067   * Assert that a gauge exists and that it's value is equal to the expected value.
068   * @param name     The name of the gauge
069   * @param expected The expected value of the gauge.
070   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
071   *                 counters.
072   */
073  void assertGauge(String name, double expected, BaseSource source);
074
075  /**
076   * Assert that a gauge exists and it's value is greater than a given value
077   * @param name     The name of the gauge
078   * @param expected Value that the gauge is expected to be greater than
079   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
080   *                 counters.
081   */
082  void assertGaugeGt(String name, double expected, BaseSource source);
083
084  /**
085   * Assert that a gauge exists and it's value is less than a given value
086   * @param name     The name of the gauge
087   * @param expected Value that the gauge is expected to be less than
088   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
089   *                 counters.
090   */
091  void assertGaugeLt(String name, double expected, BaseSource source);
092
093  /**
094   * Assert that a counter exists and that it's value is equal to the expected value.
095   * @param name     The name of the counter.
096   * @param expected The expected value
097   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
098   *                 counters.
099   */
100  void assertCounter(String name, long expected, BaseSource source);
101
102  /**
103   * Assert that a counter exists and that it's value is greater than the given value.
104   * @param name     The name of the counter.
105   * @param expected The value the counter is expected to be greater than.
106   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
107   *                 counters.
108   */
109  void assertCounterGt(String name, long expected, BaseSource source);
110
111  /**
112   * Assert that a counter exists and that it's value is less than the given value.
113   * @param name     The name of the counter.
114   * @param expected The value the counter is expected to be less than.
115   * @param source   The BaseSource{@link BaseSource} that will provide the tags, gauges, and
116   *                 counters.
117   */
118  void assertCounterLt(String name, long expected, BaseSource source);
119
120  /**
121   * Get the value of a counter.
122   * @param name   name of the counter.
123   * @param source The BaseSource{@link BaseSource} that will provide the tags, gauges, and
124   *               counters.
125   * @return long value of the counter.
126   */
127  long getCounter(String name, BaseSource source);
128
129  /**
130   * Check if a dynamic counter exists.
131   * @param name   name of the counter.
132   * @param source The BaseSource{@link BaseSource} that will provide the tags, gauges, and
133   *               counters.
134   * @return boolean true if counter metric exists.
135   */
136  boolean checkCounterExists(String name, BaseSource source);
137
138  /**
139   * Check if a gauge exists.
140   * @param name   name of the gauge.
141   * @param source The BaseSource{@link BaseSource} that will provide the tags, gauges, and
142   *               counters.
143   * @return boolean true if gauge metric exists.
144   */
145  boolean checkGaugeExists(String name, BaseSource source);
146
147  /**
148   * Get the value of a gauge as a double.
149   * @param name   name of the gauge.
150   * @param source The BaseSource{@link BaseSource} that will provide the tags, gauges, and
151   *               counters.
152   * @return double value of the gauge.
153   */
154  double getGaugeDouble(String name, BaseSource source);
155
156  /**
157   * Get the value of a gauge as a long.
158   * @param name   name of the gauge.
159   * @param source The BaseSource{@link BaseSource} that will provide the tags, gauges, and
160   *               counters.
161   * @return long value of the gauge.
162   */
163  long getGaugeLong(String name, BaseSource source);
164
165  /**
166   * Generates a representation of all metrics exported by the given {@code source}.
167   * @param source The {@link BaseSource} that will provide the metrics.
168   * @return A representation of the metrics as a String.
169   */
170  String toDebugString(BaseSource source);
171}