Amend HBASE-26187 UTs, adding a check for Split procedure completion before proceeding with test logic. (#3598)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Wellington Ramos Chevreuil 2021-08-18 15:39:00 +01:00 committed by GitHub
parent 33e15a261d
commit f2e2140b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.regionserver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
@ -30,6 +31,8 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure;
import org.apache.hadoop.hbase.procedure2.Procedure;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
@ -98,6 +101,7 @@ public class TestDirectStoreSplitsMerges {
TEST_UTIL.createTable(table, FAMILY_NAME);
//splitting the table first
TEST_UTIL.getAdmin().split(table, Bytes.toBytes("002"));
waitForSplitProcComplete(1000, 10);
//Add data and flush to create files in the two different regions
putThreeRowsAndFlush(table);
List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(table);
@ -176,6 +180,7 @@ public class TestDirectStoreSplitsMerges {
TEST_UTIL.createTable(table, FAMILY_NAME);
//splitting the table first
TEST_UTIL.getAdmin().split(table, Bytes.toBytes("002"));
waitForSplitProcComplete(1000, 10);
//Add data and flush to create files in the two different regions
putThreeRowsAndFlush(table);
List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(table);
@ -202,6 +207,22 @@ public class TestDirectStoreSplitsMerges {
mergeRegionFs.commitMergedRegion();
}
private void waitForSplitProcComplete(int attempts, int waitTime) throws Exception {
List<Procedure<?>> procedures = TEST_UTIL.getHBaseCluster().getMaster().getProcedures();
if(procedures.size()>0) {
Procedure splitProc = procedures.stream().
filter(p -> p instanceof SplitTableRegionProcedure).findFirst().get();
int count = 0;
while ((splitProc.isWaiting() || splitProc.isRunnable()) && count < attempts) {
synchronized (splitProc) {
splitProc.wait(waitTime);
}
count++;
}
assertTrue(splitProc.isSuccess());
}
}
private void mergeFileFromRegion(HRegionFileSystem regionFS, HRegion regionToMerge,
HStoreFile file) throws IOException {
Path mergedFile = regionFS.mergeStoreFile(regionToMerge.getRegionInfo(),