From 655468b9b2ee1a2abf5e0f63293b3136c9e679cb Mon Sep 17 00:00:00 2001 From: zhangduo Date: Thu, 22 Mar 2018 22:09:21 +0800 Subject: [PATCH] HBASE-20252 Admin.move will not fail if we move region to a nonexistent region server --- .../hadoop/hbase/regionserver/TestRegionMove.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java index 86c1e61..56d70a8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java @@ -23,10 +23,10 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotEnabledException; import org.apache.hadoop.hbase.client.Admin; @@ -34,7 +34,8 @@ import org.apache.hadoop.hbase.client.DoNotRetryRegionException; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.Table; -import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.testclassification.MasterTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.AfterClass; import org.junit.Before; @@ -46,10 +47,7 @@ import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.junit.rules.TestName; -/** - * Test move fails when table disabled - */ -@Category({LargeTests.class}) +@Category({ MasterTests.class, MediumTests.class }) public class TestRegionMove { @ClassRule @@ -62,12 +60,10 @@ public class TestRegionMove { @Rule public TestName name = new TestName(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - public static Configuration CONF ; - protected static final String F1 = "f1"; + private static final String F1 = "f1"; // Test names - protected TableName tableName; - protected String method; + private TableName tableName; @BeforeClass public static void startCluster() throws Exception { @@ -81,11 +77,12 @@ public class TestRegionMove { @Before public void setup() throws IOException { - CONF = TEST_UTIL.getConfiguration(); - method = name.getMethodName(); - tableName = TableName.valueOf(method); + tableName = TableName.valueOf(name.getMethodName()); } + /** + * Test move fails when table disabled + */ @Test public void testDisableAndMove() throws Exception { Admin admin = TEST_UTIL.getAdmin(); @@ -139,4 +136,13 @@ public class TestRegionMove { // Move the region to the other RS -- should fail admin.move(regionToMove.getEncodedNameAsBytes(), Bytes.toBytes(rs2.getServerName().toString())); } + + @Test + public void testMoveToNonexistentServer() throws IOException, InterruptedException { + TEST_UTIL.createTable(tableName, Bytes.toBytes(F1)); + RegionInfo region = + TEST_UTIL.getMiniHBaseCluster().getRegions(tableName).get(0).getRegionInfo(); + TEST_UTIL.getAdmin().move(region.getEncodedNameAsBytes(), Bytes.toBytes( + ServerName.valueOf("hbase.apache.org", 80, System.currentTimeMillis()).getServerName())); + } } -- 2.7.4