HBASE-26700 The way we bypass broken track file is not enough in StoreFileListFile...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestMetricsUserAggregate.java
blob501ca726cd317a329734e054aecc3a0380a1a9e9
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
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.regionserver;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23 import java.security.PrivilegedAction;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.CompatibilityFactory;
26 import org.apache.hadoop.hbase.HBaseClassTestRule;
27 import org.apache.hadoop.hbase.HBaseConfiguration;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.security.User;
30 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
31 import org.apache.hadoop.hbase.testclassification.LargeTests;
32 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.ClassRule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
39 @Category({RegionServerTests.class, LargeTests.class})
40 public class TestMetricsUserAggregate {
42 @ClassRule public static final HBaseClassTestRule CLASS_RULE =
43 HBaseClassTestRule.forClass(TestMetricsUserAggregate.class);
45 private static MetricsAssertHelper HELPER =
46 CompatibilityFactory.getInstance(MetricsAssertHelper.class);
48 private MetricsRegionServerWrapperStub wrapper;
49 private MetricsRegionServer rsm;
50 private MetricsUserAggregate userAgg;
51 private TableName tableName = TableName.valueOf("testUserAggregateMetrics");
53 @BeforeClass
54 public static void classSetUp() {
55 HELPER.init();
58 @Before
59 public void setUp() {
60 wrapper = new MetricsRegionServerWrapperStub();
61 Configuration conf = HBaseConfiguration.create();
62 rsm = new MetricsRegionServer(wrapper,conf , null);
63 userAgg = (MetricsUserAggregate)rsm.getMetricsUserAggregate();
66 private void doOperations() {
67 for (int i=0; i < 10; i ++) {
68 rsm.updateGet(tableName,10);
70 for (int i=0; i < 11; i ++) {
71 rsm.updateScanTime(tableName,11);
73 for (int i=0; i < 12; i ++) {
74 rsm.updatePut(tableName,12);
76 for (int i=0; i < 13; i ++) {
77 rsm.updateDelete(tableName,13);
79 for (int i=0; i < 14; i ++) {
80 rsm.updateIncrement(tableName,14);
82 for (int i=0; i < 15; i ++) {
83 rsm.updateAppend(tableName,15);
85 for (int i=0; i < 16; i ++) {
86 rsm.updateReplay(16);
90 @Test
91 public void testPerUserOperations() {
92 Configuration conf = HBaseConfiguration.create();
93 // If metrics for users is not enabled, this test doesn't make sense.
94 if (!conf.getBoolean(MetricsUserAggregateFactory.METRIC_USER_ENABLED_CONF,
95 MetricsUserAggregateFactory.DEFAULT_METRIC_USER_ENABLED_CONF)) {
96 return;
98 User userFoo = User.createUserForTesting(conf, "FOO", new String[0]);
99 User userBar = User.createUserForTesting(conf, "BAR", new String[0]);
101 userFoo.getUGI().doAs(new PrivilegedAction<Void>() {
102 @Override
103 public Void run() {
104 doOperations();
105 return null;
109 userBar.getUGI().doAs(new PrivilegedAction<Void>() {
110 @Override
111 public Void run() {
112 doOperations();
113 return null;
117 HELPER.assertCounter("userfoometricgetnumops", 10, userAgg.getSource());
118 HELPER.assertCounter("userfoometricscantimenumops", 11, userAgg.getSource());
119 HELPER.assertCounter("userfoometricputnumops", 12, userAgg.getSource());
120 HELPER.assertCounter("userfoometricdeletenumops", 13, userAgg.getSource());
121 HELPER.assertCounter("userfoometricincrementnumops", 14, userAgg.getSource());
122 HELPER.assertCounter("userfoometricappendnumops", 15, userAgg.getSource());
123 HELPER.assertCounter("userfoometricreplaynumops", 16, userAgg.getSource());
125 HELPER.assertCounter("userbarmetricgetnumops", 10, userAgg.getSource());
126 HELPER.assertCounter("userbarmetricscantimenumops", 11, userAgg.getSource());
127 HELPER.assertCounter("userbarmetricputnumops", 12, userAgg.getSource());
128 HELPER.assertCounter("userbarmetricdeletenumops", 13, userAgg.getSource());
129 HELPER.assertCounter("userbarmetricincrementnumops", 14, userAgg.getSource());
130 HELPER.assertCounter("userbarmetricappendnumops", 15, userAgg.getSource());
131 HELPER.assertCounter("userbarmetricreplaynumops", 16, userAgg.getSource());
134 @Test public void testLossyCountingOfUserMetrics() {
135 Configuration conf = HBaseConfiguration.create();
136 // If metrics for users is not enabled, this test doesn't make sense.
137 if (!conf.getBoolean(MetricsUserAggregateFactory.METRIC_USER_ENABLED_CONF,
138 MetricsUserAggregateFactory.DEFAULT_METRIC_USER_ENABLED_CONF)) {
139 return;
141 int noOfUsers = 10000;
142 for (int i = 1; i <= noOfUsers; i++) {
143 User.createUserForTesting(conf, "FOO" + i, new String[0]).getUGI()
144 .doAs(new PrivilegedAction<Void>() {
145 @Override public Void run() {
146 rsm.updateGet(tableName, 10);
147 return null;
151 assertTrue(
152 ((MetricsUserAggregateSourceImpl) userAgg.getSource()).getUserSources().size() <= (noOfUsers
153 / 10));
154 for (int i = 1; i <= noOfUsers / 10; i++) {
155 assertFalse(
156 HELPER.checkCounterExists("userfoo" + i + "metricgetnumops", userAgg.getSource()));
158 HELPER.assertCounter("userfoo" + noOfUsers + "metricgetnumops", 1, userAgg.getSource());