Skip to content

Commit

Permalink
Amend HBASE-26187 UTs, adding a check for Split procedure completion …
Browse files Browse the repository at this point in the history
…before proceeding with test logic. (#3598)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
  • Loading branch information
wchevreuil authored Aug 18, 2021
1 parent 33e15a2 commit f2e2140
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,8 @@
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;
Expand Down Expand Up @@ -98,6 +101,7 @@ public void testMergeStoreFile() throws Exception {
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);
Expand Down Expand Up @@ -176,6 +180,7 @@ public void testCommitMergedRegion() throws Exception {
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);
Expand All @@ -202,6 +207,22 @@ public void testCommitMergedRegion() throws Exception {
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(),
Expand Down

0 comments on commit f2e2140

Please sign in to comment.