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.util.List;
021import java.util.stream.Collectors;
022import org.apache.hadoop.hbase.client.RegionInfo;
023import org.apache.hadoop.hbase.master.assignment.MergeTableRegionsProcedure;
024import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
025import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
026import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
027import org.apache.hadoop.hbase.testclassification.MasterTests;
028import org.apache.hadoop.hbase.testclassification.MediumTests;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.Test;
031
032import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState;
033
034@Tag(MasterTests.TAG)
035@Tag(MediumTests.TAG)
036public class TestSnapshotProcedureRIT extends TestSnapshotProcedure {
037
038  @Test
039  public void testTableInMergeWhileTakingSnapshot() throws Exception {
040    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
041    List<RegionInfo> regions = master.getAssignmentManager().getTableRegions(TABLE_NAME, true)
042      .stream().sorted(RegionInfo.COMPARATOR).collect(Collectors.toList());
043    MergeTableRegionsProcedure mergeProc = new MergeTableRegionsProcedure(procExec.getEnvironment(),
044      new RegionInfo[] { regions.get(0), regions.get(1) }, false);
045    long mergeProcId = procExec.submitProcedure(mergeProc);
046    // wait until merge region procedure running
047    TEST_UTIL.waitFor(10000,
048      () -> procExec.getProcedure(mergeProcId).getState() == ProcedureState.RUNNABLE);
049    SnapshotProcedure sp = new SnapshotProcedure(procExec.getEnvironment(), snapshotProto);
050    long snapshotProcId = procExec.submitProcedure(sp);
051    TEST_UTIL.waitFor(2000, 1000, () -> procExec.getProcedure(snapshotProcId) != null);
052    ProcedureTestingUtility.waitProcedure(procExec, snapshotProcId);
053    SnapshotTestingUtils.confirmSnapshotValid(TEST_UTIL, snapshotProto, TABLE_NAME, CF);
054  }
055}