You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2018/08/23 01:46:04 UTC
[3/4] hbase git commit: HBASE-21076 refactor TestTableResource to ask
for a multi-region table instead of relying on a split operation.
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 <zh...@apache.org>
Signed-off-by: Ted Yu <ty...@apache.org>
Signed-off-by: Andrew Purtell <ap...@apache.org>
(cherry picked from commit 6b18e39f30b30ad2aa027eefbf520f2c5b1de490)
(cherry picked from commit 63f2d3cbdc8151f5f61f33e0a078c51b9ac076a5)
Conflicts:
hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/05460c93
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/05460c93
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/05460c93
Branch: refs/heads/branch-1.3
Commit: 05460c9370c175729c10b1f0ad6d91b15e5660ac
Parents: 89cfe88
Author: Sean Busbey <bu...@apache.org>
Authored: Mon Aug 20 13:43:25 2018 -0500
Committer: Sean Busbey <bu...@apache.org>
Committed: Wed Aug 22 19:56:52 2018 -0500
----------------------------------------------------------------------
.../hadoop/hbase/rest/TestTableResource.java | 55 ++++++--------------
1 file changed, 17 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/05460c93/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
----------------------------------------------------------------------
diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
index 3abcb4a..77ebcdc 100644
--- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
+++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java
@@ -35,15 +35,11 @@ import javax.xml.bind.JAXBException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
-import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.Waiter;
-import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put;
@@ -58,7 +54,6 @@ import org.apache.hadoop.hbase.rest.model.TableModel;
import org.apache.hadoop.hbase.rest.model.TableRegionModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -68,9 +63,10 @@ import org.junit.experimental.categories.Category;
public class TestTableResource {
private static final Log LOG = LogFactory.getLog(TestTableResource.class);
- private static TableName TABLE = TableName.valueOf("TestTableResource");
- private static String COLUMN_FAMILY = "test";
- private static String COLUMN = COLUMN_FAMILY + ":qualifier";
+ private static final TableName TABLE = TableName.valueOf("TestTableResource");
+ private static final String COLUMN_FAMILY = "test";
+ private static final String COLUMN = COLUMN_FAMILY + ":qualifier";
+ private static final int NUM_REGIONS = 4;
private static List<HRegionLocation> regionMap;
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -90,13 +86,7 @@ public class TestTableResource {
TableInfoModel.class,
TableListModel.class,
TableRegionModel.class);
- Admin admin = TEST_UTIL.getHBaseAdmin();
- if (admin.tableExists(TABLE)) {
- return;
- }
- HTableDescriptor htd = new HTableDescriptor(TABLE);
- htd.addFamily(new HColumnDescriptor(COLUMN_FAMILY));
- admin.createTable(htd);
+ TEST_UTIL.createMultiRegionTable(TABLE, Bytes.toBytes(COLUMN_FAMILY), NUM_REGIONS);
byte[] k = new byte[3];
byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(COLUMN));
List<Put> puts = new ArrayList<>();
@@ -113,35 +103,20 @@ public class TestTableResource {
}
}
}
+
Connection connection = TEST_UTIL.getConnection();
Table table = connection.getTable(TABLE);
table.put(puts);
table.close();
- // get the initial layout (should just be one region)
-
- final RegionLocator regionLocator = connection.getRegionLocator(TABLE);
- List<HRegionLocation> m = regionLocator.getAllRegionLocations();
- assertEquals(m.size(), 1);
- // tell the master to split the table
- admin.split(TABLE);
- // give some time for the split to happen
- long timeout = EnvironmentEdgeManager.currentTime() + (15 * 1000);
- TEST_UTIL.waitFor(timeout, 250, new Waiter.Predicate<IOException>() {
- @Override
- public boolean evaluate() throws IOException {
- List<HRegionLocation> regionLocations = regionLocator.getAllRegionLocations();
- return regionLocations.size() == 2 && regionLocations.get(0).getServerName() != null
- && regionLocations.get(1).getServerName() != null;
- }
- });
- m = regionLocator.getAllRegionLocations();
+ RegionLocator regionLocator = connection.getRegionLocator(TABLE);
+ List<HRegionLocation> m = regionLocator.getAllRegionLocations();
- // should have two regions now
- assertEquals(2, m.size());
+ // should have four regions now
+ assertEquals(NUM_REGIONS, m.size());
regionMap = m;
- LOG.info("regions: " + regionMap);
+ LOG.error("regions: " + regionMap);
regionLocator.close();
}
@@ -172,10 +147,14 @@ public class TestTableResource {
while (regions.hasNext()) {
TableRegionModel region = regions.next();
boolean found = false;
+ LOG.debug("looking for region " + region.getName());
for (HRegionLocation e: regionMap) {
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();
+ LOG.debug("comparing to region " + hriRegionName);
if (hriRegionName.equals(regionName)) {
found = true;
byte[] startKey = hri.getStartKey();
@@ -192,7 +171,7 @@ public class TestTableResource {
break;
}
}
- assertTrue(found);
+ assertTrue("Couldn't find region " + region.getName(), found);
}
}