View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  import java.io.IOException;
23  import org.apache.hadoop.hbase.CompatibilityFactory;
24  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
25  import org.apache.hadoop.hbase.TableName;
26  import org.apache.hadoop.hbase.test.MetricsAssertHelper;
27  import org.apache.hadoop.hbase.testclassification.RegionServerTests;
28  import org.apache.hadoop.hbase.testclassification.SmallTests;
29  import org.junit.Test;
30  import org.junit.experimental.categories.Category;
31  
32  @Category({RegionServerTests.class, SmallTests.class})
33  public class TestMetricsTableLatencies {
34  
35    public static MetricsAssertHelper HELPER =
36        CompatibilityFactory.getInstance(MetricsAssertHelper.class);
37  
38    @Test
39    public void testTableWrapperAggregateMetrics() throws IOException {
40      TableName tn1 = TableName.valueOf("table1");
41      TableName tn2 = TableName.valueOf("table2");
42      MetricsTableLatencies latencies = CompatibilitySingletonFactory.getInstance(
43          MetricsTableLatencies.class);
44      assertTrue("'latencies' is actually " + latencies.getClass(),
45          latencies instanceof MetricsTableLatenciesImpl);
46      MetricsTableLatenciesImpl latenciesImpl = (MetricsTableLatenciesImpl) latencies;
47      RegionServerTableMetrics tableMetrics = new RegionServerTableMetrics();
48  
49      // Metrics to each table should be disjoint
50      // N.B. each call to assertGauge removes all previously acquired metrics so we have to
51      //   make the metrics call and then immediately verify it. Trying to do multiple metrics
52      //   updates followed by multiple verifications will fail on the 2nd verification (as the
53      //   first verification cleaned the data structures in MetricsAssertHelperImpl).
54      tableMetrics.updateGet(tn1, 500L);
55      HELPER.assertGauge(MetricsTableLatenciesImpl.qualifyMetricsName(
56          tn1, MetricsTableLatencies.GET_TIME + "_" + "999th_percentile"), 500L, latenciesImpl);
57      tableMetrics.updatePut(tn1, 50L);
58      HELPER.assertGauge(MetricsTableLatenciesImpl.qualifyMetricsName(
59          tn1, MetricsTableLatencies.PUT_TIME + "_" + "99th_percentile"), 50L, latenciesImpl);
60  
61      tableMetrics.updateGet(tn2, 300L);
62      HELPER.assertGauge(MetricsTableLatenciesImpl.qualifyMetricsName(
63          tn2, MetricsTableLatencies.GET_TIME + "_" + "999th_percentile"), 300L, latenciesImpl);
64      tableMetrics.updatePut(tn2, 75L);
65      HELPER.assertGauge(MetricsTableLatenciesImpl.qualifyMetricsName(
66          tn2, MetricsTableLatencies.PUT_TIME + "_" + "99th_percentile"), 75L, latenciesImpl);
67    }
68  }