HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestServerCrashProcedureCarryingMetaStuck.java
blob7301c750f1736687a7effc68ba1bcac9af0011da
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.master;
20 import java.util.concurrent.CompletableFuture;
21 import java.util.concurrent.TimeUnit;
22 import org.apache.hadoop.hbase.HBaseClassTestRule;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.client.AsyncAdmin;
26 import org.apache.hadoop.hbase.client.AsyncConnection;
27 import org.apache.hadoop.hbase.client.ConnectionFactory;
28 import org.apache.hadoop.hbase.client.RegionInfo;
29 import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure;
30 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
31 import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
32 import org.apache.hadoop.hbase.regionserver.HRegionServer;
33 import org.apache.hadoop.hbase.testclassification.MasterTests;
34 import org.apache.hadoop.hbase.testclassification.MediumTests;
35 import org.apache.hadoop.hbase.util.Bytes;
36 import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
37 import org.junit.AfterClass;
38 import org.junit.BeforeClass;
39 import org.junit.ClassRule;
40 import org.junit.Test;
41 import org.junit.experimental.categories.Category;
43 @Category({ MasterTests.class, MediumTests.class })
44 public class TestServerCrashProcedureCarryingMetaStuck {
46 @ClassRule
47 public static final HBaseClassTestRule CLASS_RULE =
48 HBaseClassTestRule.forClass(TestServerCrashProcedureCarryingMetaStuck.class);
50 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
52 @BeforeClass
53 public static void setUp() throws Exception {
54 UTIL.startMiniCluster(3);
55 UTIL.getAdmin().balancerSwitch(false, true);
58 @AfterClass
59 public static void tearDown() throws Exception {
60 UTIL.shutdownMiniCluster();
63 @Test
64 public void test() throws Exception {
65 RegionServerThread rsThread = null;
66 for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
67 if (!t.getRegionServer().getRegions(TableName.META_TABLE_NAME).isEmpty()) {
68 rsThread = t;
69 break;
72 HRegionServer rs = rsThread.getRegionServer();
73 RegionInfo hri = rs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo();
74 HMaster master = UTIL.getMiniHBaseCluster().getMaster();
75 ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor();
76 DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri);
77 long procId = master.getMasterProcedureExecutor().submitProcedure(proc);
78 proc.waitUntilArrive();
79 try (AsyncConnection conn =
80 ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
81 AsyncAdmin admin = conn.getAdmin();
82 CompletableFuture<Void> future = admin.move(hri.getRegionName());
83 rs.abort("For testing!");
85 UTIL.waitFor(30000,
86 () -> executor.getProcedures().stream()
87 .filter(p -> p instanceof TransitRegionStateProcedure)
88 .map(p -> (TransitRegionStateProcedure) p)
89 .anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName())));
90 proc.resume();
91 UTIL.waitFor(30000, () -> executor.isFinished(procId));
92 // see whether the move region procedure can finish properly
93 future.get(30, TimeUnit.SECONDS);