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.assignment; 019 020import java.io.IOException; 021import java.util.concurrent.CompletableFuture; 022import java.util.concurrent.ExecutionException; 023import java.util.concurrent.TimeUnit; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.HConstants; 028import org.apache.hadoop.hbase.ProcedureTestUtil; 029import org.apache.hadoop.hbase.TableName; 030import org.apache.hadoop.hbase.client.AsyncAdmin; 031import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; 032import org.apache.hadoop.hbase.client.TableDescriptorBuilder; 033import org.apache.hadoop.hbase.master.HMaster; 034import org.apache.hadoop.hbase.master.MasterServices; 035import org.apache.hadoop.hbase.master.region.MasterRegion; 036import org.apache.hadoop.hbase.testclassification.MasterTests; 037import org.apache.hadoop.hbase.testclassification.MediumTests; 038import org.apache.hadoop.hbase.util.Bytes; 039import org.junit.AfterClass; 040import org.junit.BeforeClass; 041import org.junit.ClassRule; 042import org.junit.Test; 043import org.junit.experimental.categories.Category; 044 045/** 046 * Testcase for HBASE-23079. 047 */ 048@Category({ MasterTests.class, MediumTests.class }) 049public class TestOpenRegionProcedureBackoff { 050 051 @ClassRule 052 public static final HBaseClassTestRule CLASS_RULE = 053 HBaseClassTestRule.forClass(TestOpenRegionProcedureBackoff.class); 054 055 private static volatile boolean FAIL = false; 056 057 private static final class AssignmentManagerForTest extends AssignmentManager { 058 059 public AssignmentManagerForTest(MasterServices master, MasterRegion masterRegion) { 060 super(master, masterRegion); 061 } 062 063 @Override 064 void persistToMeta(RegionStateNode regionNode) throws IOException { 065 if (FAIL) { 066 throw new IOException("Inject Error!"); 067 } 068 super.persistToMeta(regionNode); 069 } 070 } 071 072 public static final class HMasterForTest extends HMaster { 073 074 public HMasterForTest(Configuration conf) throws IOException { 075 super(conf); 076 } 077 078 @Override 079 protected AssignmentManager createAssignmentManager(MasterServices master, 080 MasterRegion masterRegion) { 081 return new AssignmentManagerForTest(master, masterRegion); 082 } 083 } 084 085 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 086 087 private static TableName NAME = TableName.valueOf("Open"); 088 089 private static byte[] CF = Bytes.toBytes("cf"); 090 091 @BeforeClass 092 public static void setUp() throws Exception { 093 Configuration conf = UTIL.getConfiguration(); 094 conf.setClass(HConstants.MASTER_IMPL, HMasterForTest.class, HMaster.class); 095 UTIL.startMiniCluster(1); 096 UTIL.waitTableAvailable(TableName.META_TABLE_NAME); 097 } 098 099 @AfterClass 100 public static void tearDown() throws Exception { 101 UTIL.shutdownMiniCluster(); 102 } 103 104 private void assertBackoffIncrease() throws IOException, InterruptedException { 105 ProcedureTestUtil.waitUntilProcedureWaitingTimeout(UTIL, OpenRegionProcedure.class, 30000); 106 ProcedureTestUtil.waitUntilProcedureTimeoutIncrease(UTIL, OpenRegionProcedure.class, 2); 107 } 108 109 @Test 110 public void testBackoff() throws IOException, InterruptedException, ExecutionException { 111 FAIL = true; 112 AsyncAdmin admin = UTIL.getAsyncConnection().getAdminBuilder() 113 .setRpcTimeout(5, TimeUnit.MINUTES).setOperationTimeout(10, TimeUnit.MINUTES).build(); 114 CompletableFuture<?> future = admin.createTable(TableDescriptorBuilder.newBuilder(NAME) 115 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)).build()); 116 assertBackoffIncrease(); 117 FAIL = false; 118 future.get(); 119 UTIL.waitTableAvailable(NAME); 120 } 121}