001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master; 019 020import java.io.IOException; 021import java.util.Optional; 022import org.apache.hadoop.hbase.HBaseClassTestRule; 023import org.apache.hadoop.hbase.HBaseTestingUtility; 024import org.apache.hadoop.hbase.HConstants; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.client.RegionInfo; 027import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; 028import org.apache.hadoop.hbase.coprocessor.ObserverContext; 029import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; 030import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; 031import org.apache.hadoop.hbase.coprocessor.RegionObserver; 032import org.apache.hadoop.hbase.testclassification.LargeTests; 033import org.apache.hadoop.hbase.testclassification.MasterTests; 034import org.junit.BeforeClass; 035import org.junit.ClassRule; 036import org.junit.Test; 037import org.junit.experimental.categories.Category; 038import org.slf4j.Logger; 039import org.slf4j.LoggerFactory; 040 041@Category({ MasterTests.class, LargeTests.class }) 042public class TestMasterHandlerFullWhenTransitRegion { 043 044 private static Logger LOG = 045 LoggerFactory.getLogger(TestMasterHandlerFullWhenTransitRegion.class.getName()); 046 047 @ClassRule 048 public static final HBaseClassTestRule CLASS_RULE = 049 HBaseClassTestRule.forClass(TestMasterHandlerFullWhenTransitRegion.class); 050 051 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); 052 053 private static final String TABLENAME = "table"; 054 055 @BeforeClass 056 public static void setUp() throws Exception { 057 UTIL.getConfiguration().setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, 058 DelayOpenCP.class.getName()); 059 // set handler number to 1. 060 UTIL.getConfiguration().setInt(HConstants.REGION_SERVER_HANDLER_COUNT, 1); 061 UTIL.startMiniCluster(2); 062 UTIL.createTable(TableName.valueOf(TABLENAME), "fa"); 063 } 064 065 @Test 066 public void test() throws Exception { 067 RegionInfo regionInfo = UTIL.getAdmin().getRegions(TableName.valueOf(TABLENAME)).get(0); 068 // See HBASE-21754 069 // There is Only one handler, if ReportRegionStateTransitionRequest executes in the same kind 070 // of thread with moveRegion, it will lock each other. Making the move operation can not finish. 071 UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes()); 072 LOG.info("Region move complete"); 073 } 074 075 /** 076 * Make open region very slow 077 */ 078 public static class DelayOpenCP implements RegionCoprocessor, RegionObserver { 079 080 @Override 081 public void preOpen(ObserverContext<RegionCoprocessorEnvironment> c) throws IOException { 082 try { 083 if (!c.getEnvironment().getRegion().getRegionInfo().getTable().isSystemTable()) { 084 LOG.info("begin to sleep"); 085 Thread.sleep(10000); 086 LOG.info("finish sleep"); 087 } 088 } catch (Throwable t) { 089 090 } 091 } 092 093 @Override 094 public Optional<RegionObserver> getRegionObserver() { 095 return Optional.of(this); 096 } 097 } 098 099}