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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import static org
.junit
.Assert
.assertTrue
;
22 import java
.io
.IOException
;
24 import org
.apache
.hadoop
.hbase
.CompatibilityFactory
;
25 import org
.apache
.hadoop
.hbase
.CompatibilitySingletonFactory
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.TableName
;
28 import org
.apache
.hadoop
.hbase
.test
.MetricsAssertHelper
;
29 import org
.apache
.hadoop
.hbase
.testclassification
.RegionServerTests
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
35 @Category({RegionServerTests
.class, SmallTests
.class})
36 public class TestMetricsTableLatencies
{
39 public static final HBaseClassTestRule CLASS_RULE
=
40 HBaseClassTestRule
.forClass(TestMetricsTableLatencies
.class);
42 public static MetricsAssertHelper HELPER
=
43 CompatibilityFactory
.getInstance(MetricsAssertHelper
.class);
46 public void testTableWrapperAggregateMetrics() throws IOException
{
47 TableName tn1
= TableName
.valueOf("table1");
48 TableName tn2
= TableName
.valueOf("table2");
49 MetricsTableLatencies latencies
= CompatibilitySingletonFactory
.getInstance(
50 MetricsTableLatencies
.class);
51 assertTrue("'latencies' is actually " + latencies
.getClass(),
52 latencies
instanceof MetricsTableLatenciesImpl
);
53 MetricsTableLatenciesImpl latenciesImpl
= (MetricsTableLatenciesImpl
) latencies
;
54 RegionServerTableMetrics tableMetrics
= new RegionServerTableMetrics();
56 // Metrics to each table should be disjoint
57 // N.B. each call to assertGauge removes all previously acquired metrics so we have to
58 // make the metrics call and then immediately verify it. Trying to do multiple metrics
59 // updates followed by multiple verifications will fail on the 2nd verification (as the
60 // first verification cleaned the data structures in MetricsAssertHelperImpl).
61 tableMetrics
.updateGet(tn1
, 500L);
62 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
63 tn1
, MetricsTableLatencies
.GET_TIME
+ "_" + "999th_percentile"), 500L, latenciesImpl
);
64 tableMetrics
.updatePut(tn1
, 50L);
65 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
66 tn1
, MetricsTableLatencies
.PUT_TIME
+ "_" + "99th_percentile"), 50L, latenciesImpl
);
68 tableMetrics
.updateGet(tn2
, 300L);
69 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
70 tn2
, MetricsTableLatencies
.GET_TIME
+ "_" + "999th_percentile"), 300L, latenciesImpl
);
71 tableMetrics
.updatePut(tn2
, 75L);
72 HELPER
.assertGauge(MetricsTableLatenciesImpl
.qualifyMetricsName(
73 tn2
, MetricsTableLatencies
.PUT_TIME
+ "_" + "99th_percentile"), 75L, latenciesImpl
);