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