1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with 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 19 package org.apache.hadoop.hbase.test; 20 21 import org.apache.hadoop.hbase.metrics.BaseSource; 22 23 /** Interface of a class to make assertions about metrics values. */ 24 public interface MetricsAssertHelper { 25 26 /** 27 * Init helper. This method will make sure that the metrics system is set 28 * up for tests. 29 */ 30 void init(); 31 32 /** 33 * Assert that a tag exists and has a given value. 34 * 35 * @param name The name of the tag. 36 * @param expected The expected value 37 * @param source The BaseSource{@link BaseSource} that will provide the tags, 38 * gauges, and counters. 39 */ 40 void assertTag(String name, String expected, BaseSource source); 41 42 /** 43 * Assert that a gauge exists and that it's value is equal to the expected value. 44 * 45 * @param name The name of the gauge 46 * @param expected The expected value of the gauge. 47 * @param source The BaseSource{@link BaseSource} that will provide the tags, 48 * gauges, and counters. 49 */ 50 void assertGauge(String name, long expected, BaseSource source); 51 52 /** 53 * Assert that a gauge exists and it's value is greater than a given value 54 * 55 * @param name The name of the gauge 56 * @param expected Value that the gauge is expected to be greater than 57 * @param source The BaseSource{@link BaseSource} that will provide the tags, 58 * gauges, and counters. 59 */ 60 void assertGaugeGt(String name, long expected, BaseSource source); 61 62 /** 63 * Assert that a gauge exists and it's value is less than a given value 64 * 65 * @param name The name of the gauge 66 * @param expected Value that the gauge is expected to be less than 67 * @param source The BaseSource{@link BaseSource} that will provide the tags, 68 * gauges, and counters. 69 */ 70 void assertGaugeLt(String name, long expected, BaseSource source); 71 72 /** 73 * Assert that a gauge exists and that it's value is equal to the expected value. 74 * 75 * @param name The name of the gauge 76 * @param expected The expected value of the gauge. 77 * @param source The BaseSource{@link BaseSource} that will provide the tags, 78 * gauges, and counters. 79 */ 80 void assertGauge(String name, double expected, BaseSource source); 81 82 /** 83 * Assert that a gauge exists and it's value is greater than a given value 84 * 85 * @param name The name of the gauge 86 * @param expected Value that the gauge is expected to be greater than 87 * @param source The BaseSource{@link BaseSource} that will provide the tags, 88 * gauges, and counters. 89 */ 90 void assertGaugeGt(String name, double expected, BaseSource source); 91 92 /** 93 * Assert that a gauge exists and it's value is less than a given value 94 * 95 * @param name The name of the gauge 96 * @param expected Value that the gauge is expected to be less than 97 * @param source The BaseSource{@link BaseSource} that will provide the tags, 98 * gauges, and counters. 99 */ 100 void assertGaugeLt(String name, double expected, BaseSource source); 101 102 /** 103 * Assert that a counter exists and that it's value is equal to the expected value. 104 * 105 * @param name The name of the counter. 106 * @param expected The expected value 107 * @param source The BaseSource{@link BaseSource} that will provide the tags, 108 * gauges, and counters. 109 */ 110 void assertCounter(String name, long expected, BaseSource source); 111 112 /** 113 * Assert that a counter exists and that it's value is greater than the given value. 114 * 115 * @param name The name of the counter. 116 * @param expected The value the counter is expected to be greater than. 117 * @param source The BaseSource{@link BaseSource} that will provide the tags, 118 * gauges, and counters. 119 */ 120 void assertCounterGt(String name, long expected, BaseSource source); 121 122 /** 123 * Assert that a counter exists and that it's value is less than the given value. 124 * 125 * @param name The name of the counter. 126 * @param expected The value the counter is expected to be less than. 127 * @param source The BaseSource{@link BaseSource} that will provide the tags, 128 * gauges, and counters. 129 */ 130 void assertCounterLt(String name, long expected, BaseSource source); 131 132 /** 133 * Get the value of a counter. 134 * 135 * @param name name of the counter. 136 * @param source The BaseSource{@link BaseSource} that will provide the tags, 137 * gauges, and counters. 138 * @return long value of the counter. 139 */ 140 long getCounter(String name, BaseSource source); 141 142 /** 143 * Get the value of a gauge as a double. 144 * 145 * @param name name of the gauge. 146 * @param source The BaseSource{@link BaseSource} that will provide the tags, 147 * gauges, and counters. 148 * @return double value of the gauge. 149 */ 150 double getGaugeDouble(String name, BaseSource source); 151 152 /** 153 * Get the value of a gauge as a long. 154 * 155 * @param name name of the gauge. 156 * @param source The BaseSource{@link BaseSource} that will provide the tags, 157 * gauges, and counters. 158 * @return long value of the gauge. 159 */ 160 long getGaugeLong(String name, BaseSource source); 161 }