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.regionserver; 019 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.CompatibilityFactory; 022import org.apache.hadoop.hbase.HBaseClassTestRule; 023import org.apache.hadoop.hbase.test.MetricsAssertHelper; 024import org.apache.hadoop.hbase.testclassification.RegionServerTests; 025import org.apache.hadoop.hbase.testclassification.SmallTests; 026import org.junit.ClassRule; 027import org.junit.Test; 028import org.junit.experimental.categories.Category; 029 030@Category({ RegionServerTests.class, SmallTests.class }) 031public class TestMetricsRegion { 032 033 @ClassRule 034 public static final HBaseClassTestRule CLASS_RULE = 035 HBaseClassTestRule.forClass(TestMetricsRegion.class); 036 037 public MetricsAssertHelper HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class); 038 039 @Test 040 public void testRegionWrapperMetrics() { 041 MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub(), new Configuration()); 042 MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource(); 043 044 HELPER.assertGauge( 045 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 101, 046 agg); 047 HELPER.assertGauge( 048 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 049 102, agg); 050 HELPER.assertGauge( 051 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxStoreFileAge", 052 2, agg); 053 HELPER.assertGauge( 054 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_minStoreFileAge", 055 2, agg); 056 HELPER.assertGauge( 057 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_avgStoreFileAge", 058 2, agg); 059 HELPER.assertGauge( 060 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_numReferenceFiles", 061 2, agg); 062 HELPER.assertGauge( 063 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 103, 064 agg); 065 HELPER.assertCounter( 066 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_cpRequestCount", 067 108, agg); 068 HELPER 069 .assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_" 070 + "filteredReadRequestCount", 107, agg); 071 HELPER.assertCounter( 072 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 0, 073 agg); 074 mr.close(); 075 076 // test region with replica id > 0 077 mr = new MetricsRegion(new MetricsRegionWrapperStub(1), new Configuration()); 078 agg = mr.getSource().getAggregateSource(); 079 HELPER.assertGauge( 080 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_storeCount", 081 101, agg); 082 HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 083 + "_metric_storeFileCount", 102, agg); 084 HELPER.assertGauge( 085 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_memstoreSize", 086 103, agg); 087 HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 088 + "_metric_cpRequestCount", 108, agg); 089 HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 090 + "_metric_filteredReadRequestCount", 107, agg); 091 HELPER.assertCounter( 092 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_replicaid", 1, 093 agg); 094 HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 095 + "_metric_compactionsQueuedCount", 4, agg); 096 HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 097 + "_metric_flushesQueuedCount", 6, agg); 098 HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 099 + "_metric_maxCompactionQueueSize", 4, agg); 100 HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" 101 + "_metric_maxFlushQueueSize", 6, agg); 102 mr.close(); 103 } 104}