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.hbase.CompatibilityFactory; 021import org.apache.hadoop.hbase.HBaseClassTestRule; 022import org.apache.hadoop.hbase.test.MetricsAssertHelper; 023import org.apache.hadoop.hbase.testclassification.RegionServerTests; 024import org.apache.hadoop.hbase.testclassification.SmallTests; 025import org.junit.ClassRule; 026import org.junit.Test; 027import org.junit.experimental.categories.Category; 028 029@Category({RegionServerTests.class, SmallTests.class}) 030public class TestMetricsRegion { 031 032 @ClassRule 033 public static final HBaseClassTestRule CLASS_RULE = 034 HBaseClassTestRule.forClass(TestMetricsRegion.class); 035 036 037 public MetricsAssertHelper HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class); 038 039 @Test 040 public void testRegionWrapperMetrics() { 041 MetricsRegion mr = new MetricsRegion(new MetricsRegionWrapperStub()); 042 MetricsRegionAggregateSource agg = mr.getSource().getAggregateSource(); 043 044 HELPER.assertGauge( 045 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 046 101, 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", 064 103, agg); 065 HELPER.assertCounter( 066 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_" + 067 "filteredReadRequestCount", 068 107, agg); 069 HELPER.assertCounter( 070 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 071 0, agg); 072 mr.close(); 073 074 // test region with replica id > 0 075 mr = new MetricsRegion(new MetricsRegionWrapperStub(1)); 076 agg = mr.getSource().getAggregateSource(); 077 HELPER.assertGauge( 078 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeCount", 079 101, agg); 080 HELPER.assertGauge( 081 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_storeFileCount", 082 102, agg); 083 HELPER.assertGauge( 084 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_memstoreSize", 085 103, agg); 086 HELPER.assertCounter( 087 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_" + 088 "filteredReadRequestCount", 089 107, agg); 090 HELPER.assertCounter( 091 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 092 1, agg); 093 HELPER.assertCounter( 094 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_compactionsQueuedCount", 095 4, agg); 096 HELPER.assertCounter( 097 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_flushesQueuedCount", 098 6, agg); 099 HELPER.assertCounter( 100 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxCompactionQueueSize", 101 4, agg); 102 HELPER.assertCounter( 103 "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_maxFlushQueueSize", 104 6, agg); 105 mr.close(); 106 } 107}