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 org.apache.hadoop.hbase.TableName;
021import org.apache.hadoop.hbase.client.RegionInfo;
022import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
023import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
024import org.apache.hadoop.hbase.testclassification.MasterTests;
025import org.apache.hadoop.hbase.testclassification.MediumTests;
026import org.junit.jupiter.api.Tag;
027import org.junit.jupiter.api.Test;
028
029import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.DeleteTableState;
030
031@Tag(MasterTests.TAG)
032@Tag(MediumTests.TAG)
033public class TestDeleteTableWithMasterFailover extends MasterFailoverWithProceduresTestBase {
034
035  // ==========================================================================
036  // Test Delete Table
037  // ==========================================================================
038  @Test
039  public void testDeleteWithFailover() throws Exception {
040    // TODO: Should we try every step? (master failover takes long time)
041    // It is already covered by TestDeleteTableProcedure
042    // but without the master restart, only the executor/store is restarted.
043    // Without Master restart we may not find bug in the procedure code
044    // like missing "wait" for resources to be available (e.g. RS)
045    testDeleteWithFailoverAtStep(DeleteTableState.DELETE_TABLE_UNASSIGN_REGIONS.ordinal());
046  }
047
048  private void testDeleteWithFailoverAtStep(final int step) throws Exception {
049    final TableName tableName = TableName.valueOf("testDeleteWithFailoverAtStep" + step);
050
051    // create the table
052    byte[][] splitKeys = null;
053    RegionInfo[] regions = MasterProcedureTestingUtility.createTable(getMasterProcedureExecutor(),
054      tableName, splitKeys, "f1", "f2");
055    MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(),
056      tableName, regions, "f1", "f2");
057    UTIL.getAdmin().disableTable(tableName);
058
059    ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
060    ProcedureTestingUtility.setKillBeforeStoreUpdate(procExec, true);
061    ProcedureTestingUtility.setToggleKillBeforeStoreUpdate(procExec, true);
062
063    // Start the Delete procedure && kill the executor
064    long procId =
065      procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName));
066    testRecoveryAndDoubleExecution(UTIL, procId, step);
067
068    MasterProcedureTestingUtility.validateTableDeletion(UTIL.getHBaseCluster().getMaster(),
069      tableName);
070  }
071}