HBASE-21076 refactor TestTableResource to ask for a multi-region table instead of relying on a split operation.

Also correct how the test does string conversion for region names that include non-printable characters.

includes addendum.

Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Ted Yu <tyu@apache.org>
Signed-off-by: Andrew Purtell <apurtell@apache.org>

(cherry picked from commit 6b18e39f30)
(cherry picked from commit 63f2d3cbdc)
This commit is contained in:
Sean Busbey 2018-08-20 13:43:25 -05:00
parent 1120f33c38
commit 9a3093a886
1 changed files with 15 additions and 38 deletions

View File

@ -31,19 +31,15 @@ import javax.xml.bind.JAXBException;
import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.regionserver.TestEndToEndSplitTransaction;
import org.apache.hadoop.hbase.rest.client.Client; import org.apache.hadoop.hbase.rest.client.Client;
import org.apache.hadoop.hbase.rest.client.Cluster; import org.apache.hadoop.hbase.rest.client.Cluster;
import org.apache.hadoop.hbase.rest.client.Response; import org.apache.hadoop.hbase.rest.client.Response;
@ -54,7 +50,6 @@ import org.apache.hadoop.hbase.rest.model.TableRegionModel;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests; import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.StringUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.ClassRule; import org.junit.ClassRule;
@ -72,9 +67,10 @@ public class TestTableResource {
private static final Logger LOG = LoggerFactory.getLogger(TestTableResource.class); private static final Logger LOG = LoggerFactory.getLogger(TestTableResource.class);
private static TableName TABLE = TableName.valueOf("TestTableResource"); private static final TableName TABLE = TableName.valueOf("TestTableResource");
private static String COLUMN_FAMILY = "test"; private static final String COLUMN_FAMILY = "test";
private static String COLUMN = COLUMN_FAMILY + ":qualifier"; private static final String COLUMN = COLUMN_FAMILY + ":qualifier";
private static final int NUM_REGIONS = 4;
private static List<HRegionLocation> regionMap; private static List<HRegionLocation> regionMap;
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@ -94,13 +90,7 @@ public class TestTableResource {
TableInfoModel.class, TableInfoModel.class,
TableListModel.class, TableListModel.class,
TableRegionModel.class); TableRegionModel.class);
Admin admin = TEST_UTIL.getAdmin(); TEST_UTIL.createMultiRegionTable(TABLE, Bytes.toBytes(COLUMN_FAMILY), NUM_REGIONS);
if (admin.tableExists(TABLE)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TABLE);
htd.addFamily(new HColumnDescriptor(COLUMN_FAMILY));
admin.createTable(htd);
byte[] k = new byte[3]; byte[] k = new byte[3];
byte [][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(COLUMN)); byte [][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(COLUMN));
List<Put> puts = new ArrayList<>(); List<Put> puts = new ArrayList<>();
@ -117,37 +107,20 @@ public class TestTableResource {
} }
} }
} }
Connection connection = TEST_UTIL.getConnection(); Connection connection = TEST_UTIL.getConnection();
Table table = connection.getTable(TABLE); Table table = connection.getTable(TABLE);
table.put(puts); table.put(puts);
table.close(); table.close();
// get the initial layout (should just be one region)
RegionLocator regionLocator = connection.getRegionLocator(TABLE); RegionLocator regionLocator = connection.getRegionLocator(TABLE);
List<HRegionLocation> m = regionLocator.getAllRegionLocations(); List<HRegionLocation> m = regionLocator.getAllRegionLocations();
assertEquals(1, m.size());
// tell the master to split the table
admin.split(TABLE);
// give some time for the split to happen
TestEndToEndSplitTransaction.blockUntilRegionSplit(TEST_UTIL.getConfiguration(), 60000, // should have four regions now
m.get(0).getRegionInfo().getRegionName(), true); assertEquals(NUM_REGIONS, m.size());
long timeout = System.currentTimeMillis() + (15 * 1000);
while (System.currentTimeMillis() < timeout && m.size()!=2){
try {
Thread.sleep(250);
} catch (InterruptedException e) {
LOG.warn(StringUtils.stringifyException(e));
}
// check again
m = regionLocator.getAllRegionLocations();
}
// should have two regions now
assertEquals(2, m.size());
regionMap = m; regionMap = m;
LOG.info("regions: " + regionMap); LOG.error("regions: " + regionMap);
regionLocator.close(); regionLocator.close();
} }
@ -178,10 +151,14 @@ public class TestTableResource {
while (regions.hasNext()) { while (regions.hasNext()) {
TableRegionModel region = regions.next(); TableRegionModel region = regions.next();
boolean found = false; boolean found = false;
LOG.debug("looking for region " + region.getName());
for (HRegionLocation e: regionMap) { for (HRegionLocation e: regionMap) {
HRegionInfo hri = e.getRegionInfo(); HRegionInfo hri = e.getRegionInfo();
String hriRegionName = hri.getRegionNameAsString(); // getRegionNameAsString uses Bytes.toStringBinary which escapes some non-printable
// characters
String hriRegionName = Bytes.toString(hri.getRegionName());
String regionName = region.getName(); String regionName = region.getName();
LOG.debug("comparing to region " + hriRegionName);
if (hriRegionName.equals(regionName)) { if (hriRegionName.equals(regionName)) {
found = true; found = true;
byte[] startKey = hri.getStartKey(); byte[] startKey = hri.getStartKey();
@ -198,7 +175,7 @@ public class TestTableResource {
break; break;
} }
} }
assertTrue(found); assertTrue("Couldn't find region " + region.getName(), found);
} }
} }