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 038 public MetricsAssertHelper HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class); 039 040 @Test 041 public void testRegionWrapperMetrics() { 042 MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub(), new Configuration()); 043 MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource(); 044 045 HELPER.assertGauge( 046 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 047 101, agg); 048 HELPER.assertGauge( 049 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 050 102, agg); 051 HELPER.assertGauge( 052 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxStoreFileAge", 053 2, agg); 054 HELPER.assertGauge( 055 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_minStoreFileAge", 056 2, agg); 057 HELPER.assertGauge( 058 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_avgStoreFileAge", 059 2, agg); 060 HELPER.assertGauge( 061 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_numReferenceFiles", 062 2, agg); 063 HELPER.assertGauge( 064 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 065 103, agg); 066 HELPER.assertCounter( 067 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_" + 068 "filteredReadRequestCount", 069 107, agg); 070 HELPER.assertCounter( 071 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 072 0, agg); 073 mr.close(); 074 075 // test region with replica id > 0 076 mr = new MetricsRegion(new MetricsRegionWrapperStub(1), new Configuration()); 077 agg = mr.getSource().getAggregateSource(); 078 HELPER.assertGauge( 079 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 080 101, agg); 081 HELPER.assertGauge( 082 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 083 102, agg); 084 HELPER.assertGauge( 085 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 086 103, agg); 087 HELPER.assertCounter( 088 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_" + 089 "filteredReadRequestCount", 090 107, agg); 091 HELPER.assertCounter( 092 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 093 1, agg); 094 HELPER.assertCounter( 095 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_compactionsQueuedCount", 096 4, agg); 097 HELPER.assertCounter( 098 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_flushesQueuedCount", 099 6, agg); 100 HELPER.assertCounter( 101 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxCompactionQueueSize", 102 4, agg); 103 HELPER.assertCounter( 104 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxFlushQueueSize", 105 6, agg); 106 mr.close(); 107 } 108}