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 java.io.IOException;
021import org.apache.hadoop.hbase.HBaseClassTestRule;
022import org.apache.hadoop.hbase.master.HMaster;
023import org.apache.hadoop.hbase.master.RegionState;
024import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
025import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
026import org.apache.hadoop.hbase.regionserver.HRegion;
027import org.apache.hadoop.hbase.testclassification.MasterTests;
028import org.apache.hadoop.hbase.testclassification.MediumTests;
029import org.junit.ClassRule;
030import org.junit.Test;
031import org.junit.experimental.categories.Category;
032
033@Category({ MasterTests.class, MediumTests.class })
034public class TestFlushTableProcedureMasterRestarts extends TestFlushTableProcedureBase {
035
036  @ClassRule
037  public static final HBaseClassTestRule CLASS_RULE =
038    HBaseClassTestRule.forClass(TestFlushTableProcedureMasterRestarts.class);
039
040  @Test
041  public void testMasterRestarts() throws IOException {
042    assertTableMemStoreNotEmpty();
043
044    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
045    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
046    MasterProcedureEnv env = procExec.getEnvironment();
047    FlushTableProcedure proc = new FlushTableProcedure(env, TABLE_NAME);
048    long procId = procExec.submitProcedure(proc);
049    TEST_UTIL.waitFor(5000, 1000, () -> proc.getState().getNumber() > 1);
050
051    TEST_UTIL.getHBaseCluster().killMaster(master.getServerName());
052    TEST_UTIL.getHBaseCluster().waitForMasterToStop(master.getServerName(), 30000);
053    TEST_UTIL.getHBaseCluster().startMaster();
054    TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
055
056    master = TEST_UTIL.getHBaseCluster().getMaster();
057    procExec = master.getMasterProcedureExecutor();
058    ProcedureTestingUtility.waitProcedure(procExec, procId);
059    assertTableMemStoreEmpty();
060  }
061
062  @Test
063  public void testSkipRIT() throws IOException {
064    HRegion region = TEST_UTIL.getHBaseCluster().getRegions(TABLE_NAME).get(0);
065
066    TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates()
067      .getRegionStateNode(region.getRegionInfo())
068      .setState(RegionState.State.CLOSING, RegionState.State.OPEN);
069
070    FlushRegionProcedure proc = new FlushRegionProcedure(region.getRegionInfo());
071    TEST_UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor().submitProcedure(proc);
072
073    // wait for a time which is shorter than RSProcedureDispatcher delays
074    TEST_UTIL.waitFor(5000, () -> proc.isFinished());
075  }
076}