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
066      .assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_"
067        + "filteredReadRequestCount", 107, agg);
068    HELPER.assertCounter(
069      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001_metric_replicaid", 0,
070      agg);
071    mr.close();
072
073    // test region with replica id > 0
074    mr = new MetricsRegion(new MetricsRegionWrapperStub(1), new Configuration());
075    agg = mr.getSource().getAggregateSource();
076    HELPER.assertGauge(
077      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_storeCount",
078      101, agg);
079    HELPER.assertGauge("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
080      + "_metric_storeFileCount", 102, agg);
081    HELPER.assertGauge(
082      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_memstoreSize",
083      103, agg);
084    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
085      + "_metric_filteredReadRequestCount", 107, agg);
086    HELPER.assertCounter(
087      "namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001" + "_metric_replicaid", 1,
088      agg);
089    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
090      + "_metric_compactionsQueuedCount", 4, agg);
091    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
092      + "_metric_flushesQueuedCount", 6, agg);
093    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
094      + "_metric_maxCompactionQueueSize", 4, agg);
095    HELPER.assertCounter("namespace_TestNS_table_MetricsRegionWrapperStub_region_DEADBEEF001"
096      + "_metric_maxFlushQueueSize", 6, agg);
097    mr.close();
098  }
099}