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