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 */ 018 019package org.apache.hadoop.hbase.test; 020 021import org.apache.hadoop.hbase.metrics.BaseSource; 022 023/** Interface of a class to make assertions about metrics values. */ 024public interface MetricsAssertHelper { 025 026 /** 027 * Init helper. This method will make sure that the metrics system is set 028 * up for tests. 029 */ 030 void init(); 031 032 /** 033 * Assert that a tag exists and has a given value. 034 * 035 * @param name The name of the tag. 036 * @param expected The expected value 037 * @param source The BaseSource{@link BaseSource} that will provide the tags, 038 * gauges, and counters. 039 */ 040 void assertTag(String name, String expected, BaseSource source); 041 042 /** 043 * Assert that a gauge exists and that it's value is equal to the expected value. 044 * 045 * @param name The name of the gauge 046 * @param expected The expected value of the gauge. 047 * @param source The BaseSource{@link BaseSource} that will provide the tags, 048 * gauges, and counters. 049 */ 050 void assertGauge(String name, long expected, BaseSource source); 051 052 /** 053 * Assert that a gauge exists and it's value is greater than a given value 054 * 055 * @param name The name of the gauge 056 * @param expected Value that the gauge is expected to be greater than 057 * @param source The BaseSource{@link BaseSource} that will provide the tags, 058 * gauges, and counters. 059 */ 060 void assertGaugeGt(String name, long expected, BaseSource source); 061 062 /** 063 * Assert that a gauge exists and it's value is less than a given value 064 * 065 * @param name The name of the gauge 066 * @param expected Value that the gauge is expected to be less than 067 * @param source The BaseSource{@link BaseSource} that will provide the tags, 068 * gauges, and counters. 069 */ 070 void assertGaugeLt(String name, long expected, BaseSource source); 071 072 /** 073 * Assert that a gauge exists and that it's value is equal to the expected value. 074 * 075 * @param name The name of the gauge 076 * @param expected The expected value of the gauge. 077 * @param source The BaseSource{@link BaseSource} that will provide the tags, 078 * gauges, and counters. 079 */ 080 void assertGauge(String name, double expected, BaseSource source); 081 082 /** 083 * Assert that a gauge exists and it's value is greater than a given value 084 * 085 * @param name The name of the gauge 086 * @param expected Value that the gauge is expected to be greater than 087 * @param source The BaseSource{@link BaseSource} that will provide the tags, 088 * gauges, and counters. 089 */ 090 void assertGaugeGt(String name, double expected, BaseSource source); 091 092 /** 093 * Assert that a gauge exists and it's value is less than a given value 094 * 095 * @param name The name of the gauge 096 * @param expected Value that the gauge is expected to be less than 097 * @param source The BaseSource{@link BaseSource} that will provide the tags, 098 * gauges, and counters. 099 */ 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 * Check if a dynamic counter exists. 144 * 145 * @param name name of the counter. 146 * @param source The BaseSource{@link BaseSource} that will provide the tags, 147 * gauges, and counters. 148 * @return boolean true id counter metric exists. 149 */ 150 boolean checkCounterExists(String name, BaseSource source); 151 152 /** 153 * Get the value of a gauge as a double. 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 double value of the gauge. 159 */ 160 double getGaugeDouble(String name, BaseSource source); 161 162 /** 163 * Get the value of a gauge as a long. 164 * 165 * @param name name of the gauge. 166 * @param source The BaseSource{@link BaseSource} that will provide the tags, 167 * gauges, and counters. 168 * @return long value of the gauge. 169 */ 170 long getGaugeLong(String name, BaseSource source); 171 172 /** 173 * Generates a representation of all metrics exported by the given {@code source}. 174 * @param source The {@link BaseSource} that will provide the metrics. 175 * @return A representation of the metrics as a String. 176 */ 177 String toDebugString(BaseSource source); 178}