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.
19 package org
.apache
.hadoop
.hbase
.client
;
21 import static org
.junit
.Assert
.assertEquals
;
23 import org
.apache
.hadoop
.conf
.Configuration
;
24 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
25 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
26 import org
.apache
.hadoop
.hbase
.TableName
;
27 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
28 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
29 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
30 import org
.junit
.AfterClass
;
31 import org
.junit
.BeforeClass
;
32 import org
.junit
.ClassRule
;
33 import org
.junit
.Test
;
34 import org
.junit
.experimental
.categories
.Category
;
36 @Category({ SmallTests
.class, ClientTests
.class })
37 public class TestMultiActionMetricsFromClient
{
40 public static final HBaseClassTestRule CLASS_RULE
=
41 HBaseClassTestRule
.forClass(TestMultiActionMetricsFromClient
.class);
43 private final static HBaseTestingUtil TEST_UTIL
= new HBaseTestingUtil();
44 private static final TableName TABLE_NAME
= TableName
.valueOf("test_table");
45 private static final byte[] FAMILY
= Bytes
.toBytes("fam1");
46 private static final byte[] QUALIFIER
= Bytes
.toBytes("qual");
49 public static void setUpBeforeClass() throws Exception
{
50 TEST_UTIL
.startMiniCluster(1);
51 TEST_UTIL
.getHBaseCluster().waitForActiveAndReadyMaster();
52 TEST_UTIL
.waitUntilAllRegionsAssigned(TableName
.META_TABLE_NAME
);
53 TEST_UTIL
.createTable(TABLE_NAME
, FAMILY
);
57 public static void tearDownAfterClass() throws Exception
{
58 TEST_UTIL
.shutdownMiniCluster();
62 public void testMultiMetrics() throws Exception
{
63 Configuration conf
= new Configuration(TEST_UTIL
.getConfiguration());
64 conf
.set(MetricsConnection
.CLIENT_SIDE_METRICS_ENABLED_KEY
, "true");
65 try (Connection conn
= ConnectionFactory
.createConnection(conf
)) {
66 BufferedMutator mutator
= conn
.getBufferedMutator(TABLE_NAME
);
67 byte[][] keys
= { Bytes
.toBytes("aaa"), Bytes
.toBytes("mmm"), Bytes
.toBytes("zzz") };
68 for (byte[] key
: keys
) {
70 p
.addColumn(FAMILY
, QUALIFIER
, Bytes
.toBytes(10));
77 MetricsConnection metrics
=
78 ((AsyncConnectionImpl
) conn
.toAsyncConnection()).getConnectionMetrics().get();
79 assertEquals(1, metrics
.multiTracker
.reqHist
.getCount());
80 assertEquals(3, metrics
.numActionsPerServerHist
.getSnapshot().getMean(), 1e-15);
81 assertEquals(1, metrics
.numActionsPerServerHist
.getCount());