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.procedure; 019 020import static org.junit.jupiter.api.Assertions.assertFalse; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import java.io.IOException; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.HBaseTestingUtil; 026import org.apache.hadoop.hbase.TableName; 027import org.apache.hadoop.hbase.client.RegionInfo; 028import org.apache.hadoop.hbase.client.TableDescriptor; 029import org.apache.hadoop.hbase.coprocessor.BadMasterObserverForCreateDeleteTable; 030import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; 031import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 032import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; 033import org.apache.hadoop.hbase.testclassification.MasterTests; 034import org.apache.hadoop.hbase.testclassification.MediumTests; 035import org.apache.hadoop.hbase.util.ModifyRegionUtils; 036import org.junit.jupiter.api.AfterAll; 037import org.junit.jupiter.api.BeforeAll; 038import org.junit.jupiter.api.Tag; 039import org.junit.jupiter.api.Test; 040 041@Tag(MasterTests.TAG) 042@Tag(MediumTests.TAG) 043public class TestCreateDeleteTableProcedureWithRetry { 044 045 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 046 047 private static final TableName TABLE_NAME = 048 TableName.valueOf(TestCreateDeleteTableProcedureWithRetry.class.getSimpleName()); 049 050 private static final String CF = "cf"; 051 052 @BeforeAll 053 public static void setUp() throws Exception { 054 Configuration conf = UTIL.getConfiguration(); 055 conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, 056 BadMasterObserverForCreateDeleteTable.class.getName()); 057 UTIL.startMiniCluster(1); 058 } 059 060 @AfterAll 061 public static void tearDown() throws Exception { 062 UTIL.shutdownMiniCluster(); 063 } 064 065 @Test 066 public void testCreateDeleteTableRetry() throws IOException { 067 ProcedureExecutor<MasterProcedureEnv> procExec = 068 UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor(); 069 TableDescriptor htd = MasterProcedureTestingUtility.createHTD(TABLE_NAME, CF); 070 RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, null); 071 CreateTableProcedure createProc = 072 new CreateTableProcedure(procExec.getEnvironment(), htd, regions); 073 ProcedureTestingUtility.submitAndWait(procExec, createProc); 074 assertTrue(UTIL.getAdmin().tableExists(TABLE_NAME)); 075 MasterProcedureTestingUtility.validateTableCreation(UTIL.getMiniHBaseCluster().getMaster(), 076 TABLE_NAME, regions, CF); 077 078 UTIL.getAdmin().disableTable(TABLE_NAME); 079 DeleteTableProcedure deleteProc = 080 new DeleteTableProcedure(procExec.getEnvironment(), TABLE_NAME); 081 ProcedureTestingUtility.submitAndWait(procExec, deleteProc); 082 assertFalse(UTIL.getAdmin().tableExists(TABLE_NAME)); 083 MasterProcedureTestingUtility.validateTableDeletion(UTIL.getMiniHBaseCluster().getMaster(), 084 TABLE_NAME); 085 } 086}