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; 022 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.HBaseTestingUtility; 025import org.apache.hadoop.hbase.HConstants; 026import org.apache.hadoop.hbase.TableName; 027import org.apache.hadoop.hbase.client.RegionInfo; 028import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; 029import org.apache.hadoop.hbase.coprocessor.ObserverContext; 030import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; 031import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; 032import org.apache.hadoop.hbase.coprocessor.RegionObserver; 033import org.apache.hadoop.hbase.testclassification.LargeTests; 034import org.apache.hadoop.hbase.testclassification.MasterTests; 035import org.junit.BeforeClass; 036import org.junit.ClassRule; 037import org.junit.Test; 038import org.junit.experimental.categories.Category; 039import org.slf4j.Logger; 040import org.slf4j.LoggerFactory; 041 042@Category({ MasterTests.class, LargeTests.class }) 043public class TestMasterHandlerFullWhenTransitRegion { 044 045 private static Logger LOG = LoggerFactory 046 .getLogger(TestMasterHandlerFullWhenTransitRegion.class.getName()); 047 048 @ClassRule 049 public static final HBaseClassTestRule CLASS_RULE = 050 HBaseClassTestRule.forClass(TestMasterHandlerFullWhenTransitRegion.class); 051 052 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); 053 054 private static final String TABLENAME = "table"; 055 056 @BeforeClass 057 public static void setUp() throws Exception { 058 UTIL.getConfiguration().setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, 059 DelayOpenCP.class.getName()); 060 //set handler number to 1. 061 UTIL.getConfiguration().setInt(HConstants.REGION_SERVER_HANDLER_COUNT, 1); 062 UTIL.startMiniCluster(2); 063 UTIL.createTable(TableName.valueOf(TABLENAME), "fa"); 064 } 065 066 @Test 067 public void test() throws Exception { 068 RegionInfo regionInfo = UTIL.getAdmin().getRegions(TableName.valueOf(TABLENAME)).get(0); 069 //See HBASE-21754 070 //There is Only one handler, if ReportRegionStateTransitionRequest executes in the same kind 071 // of thread with moveRegion, it will lock each other. Making the move operation can not finish. 072 UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes()); 073 LOG.info("Region move complete"); 074 } 075 076 077 /** 078 * Make open region very slow 079 */ 080 public static class DelayOpenCP implements RegionCoprocessor, RegionObserver { 081 082 @Override 083 public void preOpen(ObserverContext<RegionCoprocessorEnvironment> c) throws IOException { 084 try { 085 if (!c.getEnvironment().getRegion().getRegionInfo().getTable().isSystemTable()) { 086 LOG.info("begin to sleep"); 087 Thread.sleep(10000); 088 LOG.info("finish sleep"); 089 } 090 } catch (Throwable t) { 091 092 } 093 } 094 095 @Override 096 public Optional<RegionObserver> getRegionObserver() { 097 return Optional.of(this); 098 } 099 } 100 101}