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 / TestRemoveRegionMetrics.java
blob91a80aba02836cbacf9ccfa53819f09217ca9325
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.
18 package org.apache.hadoop.hbase.regionserver;
20 import java.io.IOException;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.CompatibilityFactory;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtil;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.NamespaceDescriptor;
27 import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.client.Admin;
30 import org.apache.hadoop.hbase.client.Put;
31 import org.apache.hadoop.hbase.client.RegionInfo;
32 import org.apache.hadoop.hbase.client.RegionLocator;
33 import org.apache.hadoop.hbase.client.Table;
34 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
35 import org.apache.hadoop.hbase.testclassification.LargeTests;
36 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
37 import org.apache.hadoop.hbase.util.Bytes;
38 import org.apache.hadoop.hbase.util.Threads;
39 import org.junit.BeforeClass;
40 import org.junit.ClassRule;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.experimental.categories.Category;
44 import org.junit.rules.TestName;
46 @Category({RegionServerTests.class, LargeTests.class})
47 public class TestRemoveRegionMetrics {
49 @ClassRule
50 public static final HBaseClassTestRule CLASS_RULE =
51 HBaseClassTestRule.forClass(TestRemoveRegionMetrics.class);
53 private static SingleProcessHBaseCluster cluster;
54 private static Configuration conf;
55 private static HBaseTestingUtil TEST_UTIL;
56 private static MetricsAssertHelper metricsHelper;
58 @Rule
59 public TestName name = new TestName();
61 @BeforeClass
62 public static void startCluster() throws Exception {
63 metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class);
64 TEST_UTIL = new HBaseTestingUtil();
65 conf = TEST_UTIL.getConfiguration();
66 conf.getLong("hbase.splitlog.max.resubmit", 0);
67 // Make the failure test faster
68 conf.setInt("zookeeper.recovery.retry", 0);
69 conf.setInt(HConstants.REGIONSERVER_INFO_PORT, -1);
71 TEST_UTIL.startMiniCluster(2);
72 cluster = TEST_UTIL.getHBaseCluster();
74 cluster.waitForActiveAndReadyMaster();
76 while (cluster.getLiveRegionServerThreads().size() < 2) {
77 Threads.sleep(100);
82 @Test
83 public void testMoveRegion() throws IOException, InterruptedException {
84 String tableNameString = name.getMethodName();
85 TableName tableName = TableName.valueOf(tableNameString);
86 Table t = TEST_UTIL.createTable(tableName, Bytes.toBytes("D"));
87 TEST_UTIL.waitUntilAllRegionsAssigned(t.getName());
88 Admin admin = TEST_UTIL.getAdmin();
89 RegionInfo regionInfo;
90 byte[] row = Bytes.toBytes("r1");
93 for (int i = 0; i < 30; i++) {
94 boolean moved = false;
95 try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
96 regionInfo = locator.getRegionLocation(row, true).getRegion();
99 int currentServerIdx = cluster.getServerWith(regionInfo.getRegionName());
100 int destServerIdx = (currentServerIdx +1)% cluster.getLiveRegionServerThreads().size();
101 HRegionServer currentServer = cluster.getRegionServer(currentServerIdx);
102 HRegionServer destServer = cluster.getRegionServer(destServerIdx);
105 // Do a put. The counters should be non-zero now
106 Put p = new Put(row);
107 p.addColumn(Bytes.toBytes("D"), Bytes.toBytes("Zero"), Bytes.toBytes("VALUE"));
108 t.put(p);
111 MetricsRegionAggregateSource currentAgg = currentServer.getRegion(regionInfo.getRegionName())
112 .getMetrics()
113 .getSource()
114 .getAggregateSource();
116 String prefix = "namespace_"+ NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR+
117 "_table_"+tableNameString +
118 "_region_" + regionInfo.getEncodedName()+
119 "_metric";
121 metricsHelper.assertCounter(prefix + "_putCount", 1, currentAgg);
124 try {
125 TEST_UTIL.moveRegionAndWait(regionInfo, destServer.getServerName());
126 moved = true;
127 } catch (IOException ioe) {
128 moved = false;
131 if (moved) {
132 MetricsRegionAggregateSource destAgg = destServer.getRegion(regionInfo.getRegionName())
133 .getMetrics()
134 .getSource()
135 .getAggregateSource();
136 metricsHelper.assertCounter(prefix + "_putCount", 0, destAgg);
140 TEST_UTIL.deleteTable(tableName);