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
;
44 * Testcase for HBASE-20634
46 @Category({ MasterTests
.class, MediumTests
.class })
47 public class TestServerCrashProcedureStuck
{
50 public static final HBaseClassTestRule CLASS_RULE
=
51 HBaseClassTestRule
.forClass(TestServerCrashProcedureStuck
.class);
53 private static final HBaseTestingUtility UTIL
= new HBaseTestingUtility();
55 private static TableName TABLE_NAME
= TableName
.valueOf("test");
57 private static byte[] CF
= Bytes
.toBytes("cf");
60 public static void setUp() throws Exception
{
61 UTIL
.startMiniCluster(3);
62 UTIL
.getAdmin().balancerSwitch(false, true);
63 UTIL
.createTable(TABLE_NAME
, CF
);
64 UTIL
.waitTableAvailable(TABLE_NAME
);
68 public static void tearDown() throws Exception
{
69 UTIL
.shutdownMiniCluster();
73 public void test() throws Exception
{
74 RegionServerThread rsThread
= null;
75 for (RegionServerThread t
: UTIL
.getMiniHBaseCluster().getRegionServerThreads()) {
76 if (!t
.getRegionServer().getRegions(TABLE_NAME
).isEmpty()) {
81 HRegionServer rs
= rsThread
.getRegionServer();
82 RegionInfo hri
= rs
.getRegions(TABLE_NAME
).get(0).getRegionInfo();
83 HMaster master
= UTIL
.getMiniHBaseCluster().getMaster();
84 ProcedureExecutor
<MasterProcedureEnv
> executor
= master
.getMasterProcedureExecutor();
85 DummyRegionProcedure proc
= new DummyRegionProcedure(executor
.getEnvironment(), hri
);
86 long procId
= master
.getMasterProcedureExecutor().submitProcedure(proc
);
87 proc
.waitUntilArrive();
88 try (AsyncConnection conn
=
89 ConnectionFactory
.createAsyncConnection(UTIL
.getConfiguration()).get()) {
90 AsyncAdmin admin
= conn
.getAdmin();
91 CompletableFuture
<Void
> future
= admin
.move(hri
.getRegionName());
92 rs
.abort("For testing!");
95 () -> executor
.getProcedures().stream()
96 .filter(p
-> p
instanceof TransitRegionStateProcedure
)
97 .map(p
-> (TransitRegionStateProcedure
) p
)
98 .anyMatch(p
-> Bytes
.equals(hri
.getRegionName(), p
.getRegion().getRegionName())));
100 UTIL
.waitFor(30000, () -> executor
.isFinished(procId
));
101 // see whether the move region procedure can finish properly
102 future
.get(30, TimeUnit
.SECONDS
);