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
.io
.IOException
;
21 import java
.util
.Optional
;
23 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
24 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
25 import org
.apache
.hadoop
.hbase
.HConstants
;
26 import org
.apache
.hadoop
.hbase
.TableName
;
27 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
28 import org
.apache
.hadoop
.hbase
.coprocessor
.CoprocessorHost
;
29 import org
.apache
.hadoop
.hbase
.coprocessor
.ObserverContext
;
30 import org
.apache
.hadoop
.hbase
.coprocessor
.RegionCoprocessor
;
31 import org
.apache
.hadoop
.hbase
.coprocessor
.RegionCoprocessorEnvironment
;
32 import org
.apache
.hadoop
.hbase
.coprocessor
.RegionObserver
;
33 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
35 import org
.junit
.BeforeClass
;
36 import org
.junit
.ClassRule
;
37 import org
.junit
.Test
;
38 import org
.junit
.experimental
.categories
.Category
;
39 import org
.slf4j
.Logger
;
40 import org
.slf4j
.LoggerFactory
;
42 @Category({ MasterTests
.class, LargeTests
.class })
43 public class TestMasterHandlerFullWhenTransitRegion
{
45 private static Logger LOG
= LoggerFactory
46 .getLogger(TestMasterHandlerFullWhenTransitRegion
.class.getName());
49 public static final HBaseClassTestRule CLASS_RULE
=
50 HBaseClassTestRule
.forClass(TestMasterHandlerFullWhenTransitRegion
.class);
52 private static final HBaseTestingUtility UTIL
= new HBaseTestingUtility();
54 private static final String TABLENAME
= "table";
57 public static void setUp() throws Exception
{
58 UTIL
.getConfiguration().setStrings(CoprocessorHost
.REGION_COPROCESSOR_CONF_KEY
,
59 DelayOpenCP
.class.getName());
60 //set handler number to 1.
61 UTIL
.getConfiguration().setInt(HConstants
.REGION_SERVER_HANDLER_COUNT
, 1);
62 UTIL
.startMiniCluster(2);
63 UTIL
.createTable(TableName
.valueOf(TABLENAME
), "fa");
67 public void test() throws Exception
{
68 RegionInfo regionInfo
= UTIL
.getAdmin().getRegions(TableName
.valueOf(TABLENAME
)).get(0);
70 //There is Only one handler, if ReportRegionStateTransitionRequest executes in the same kind
71 // of thread with moveRegion, it will lock each other. Making the move operation can not finish.
72 UTIL
.getAdmin().move(regionInfo
.getEncodedNameAsBytes());
73 LOG
.info("Region move complete");
78 * Make open region very slow
80 public static class DelayOpenCP
implements RegionCoprocessor
, RegionObserver
{
83 public void preOpen(ObserverContext
<RegionCoprocessorEnvironment
> c
) throws IOException
{
85 if (!c
.getEnvironment().getRegion().getRegionInfo().getTable().isSystemTable()) {
86 LOG
.info("begin to sleep");
88 LOG
.info("finish sleep");
90 } catch (Throwable t
) {
96 public Optional
<RegionObserver
> getRegionObserver() {
97 return Optional
.of(this);