This is an automated email from the ASF dual-hosted git repository.

zghao pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.2 by this push:
     new 3f10933  HBASE-24907 Turn off the balancer when test region admin api 
(#2278)
3f10933 is described below

commit 3f10933bf9d0e9d4f3aab636af8c6ee85aa375ff
Author: Guanghao Zhang <[email protected]>
AuthorDate: Thu Aug 20 13:42:00 2020 +0800

    HBASE-24907 Turn off the balancer when test region admin api (#2278)
    
    Signed-off-by: meiyi <[email protected]>
---
 .../hadoop/hbase/client/TestAsyncAdminBase.java    | 29 ++++++++++++----------
 .../hbase/client/TestAsyncRegionAdminApi.java      | 16 ++++++++++++
 .../hbase/client/TestAsyncRegionAdminApi2.java     | 16 ++++++++++++
 .../TestAsyncReplicationAdminApiWithClusters.java  | 17 +------------
 4 files changed, 49 insertions(+), 29 deletions(-)

diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncAdminBase.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncAdminBase.java
index c57ef8d..13762f4 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncAdminBase.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncAdminBase.java
@@ -103,24 +103,27 @@ public abstract class TestAsyncAdminBase extends 
AbstractTestUpdateConfiguration
 
   @After
   public void tearDown() throws Exception {
-    admin.listTableNames(Pattern.compile(tableName.getNameAsString() + ".*"), 
false)
-      .whenCompleteAsync((tables, err) -> {
-        if (tables != null) {
-          tables.forEach(table -> {
-            try {
-              admin.disableTable(table).join();
-            } catch (Exception e) {
-              LOG.debug("Table: " + tableName + " already disabled, so just 
deleting it.");
-            }
-            admin.deleteTable(table).join();
-          });
-        }
-      }, ForkJoinPool.commonPool()).join();
+    cleanupTables(admin, Pattern.compile(tableName.getNameAsString() + ".*"));
     if (!admin.isBalancerEnabled().join()) {
       admin.balancerSwitch(true, true);
     }
   }
 
+  protected void cleanupTables(AsyncAdmin admin, Pattern pattern) {
+    admin.listTableNames(pattern, false).whenCompleteAsync((tables, err) -> {
+      if (tables != null) {
+        tables.forEach(table -> {
+          try {
+            admin.disableTable(table).join();
+          } catch (Exception e) {
+            LOG.debug("Table: " + tableName + " already disabled, so just 
deleting it.");
+          }
+          admin.deleteTable(table).join();
+        });
+      }
+    }, ForkJoinPool.commonPool()).join();
+  }
+
   protected void createTableWithDefaultConf(TableName tableName) throws 
IOException {
     createTableWithDefaultConf(tableName, null);
   }
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java
index 33f1856..c5744bd 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 import org.apache.hadoop.conf.Configuration;
@@ -53,6 +54,8 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 import org.apache.hadoop.hbase.util.JVMClusterUtil;
 import org.apache.hadoop.hbase.util.Threads;
+import org.junit.After;
+import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -71,6 +74,19 @@ public class TestAsyncRegionAdminApi extends 
TestAsyncAdminBase {
   public static final HBaseClassTestRule CLASS_RULE =
       HBaseClassTestRule.forClass(TestAsyncRegionAdminApi.class);
 
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    TestAsyncAdminBase.setUpBeforeClass();
+    // Turn off the balancer. So region will not be moved when test region 
admin api.
+    ASYNC_CONN.getAdmin().balancerSwitch(false).join();
+  }
+
+  @Override
+  @After
+  public void tearDown() throws Exception {
+    cleanupTables(admin, Pattern.compile(tableName.getNameAsString() + ".*"));
+  }
+
   @Test
   public void testAssignRegionAndUnassignRegion() throws Exception {
     createTableWithDefaultConf(tableName);
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi2.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi2.java
index 7ea6b94..24beb14 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi2.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi2.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import org.apache.hadoop.hbase.AsyncMetaTableAccessor;
 import org.apache.hadoop.hbase.HBaseClassTestRule;
@@ -39,6 +40,8 @@ import org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Threads;
+import org.junit.After;
+import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -59,6 +62,19 @@ public class TestAsyncRegionAdminApi2 extends 
TestAsyncAdminBase {
   public static final HBaseClassTestRule CLASS_RULE =
       HBaseClassTestRule.forClass(TestAsyncRegionAdminApi2.class);
 
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    TestAsyncAdminBase.setUpBeforeClass();
+    // Turn off the balancer. So region will not be moved when test region 
admin api.
+    ASYNC_CONN.getAdmin().balancerSwitch(false).join();
+  }
+
+  @Override
+  @After
+  public void tearDown() throws Exception {
+    cleanupTables(admin, Pattern.compile(tableName.getNameAsString() + ".*"));
+  }
+
   @Test
   public void testGetRegionLocation() throws Exception {
     RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin();
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApiWithClusters.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApiWithClusters.java
index 8e60aad..dcb773c 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApiWithClusters.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApiWithClusters.java
@@ -28,8 +28,8 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.CompletionException;
-import java.util.concurrent.ForkJoinPool;
 import java.util.regex.Pattern;
+
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HBaseClassTestRule;
 import org.apache.hadoop.hbase.HBaseConfiguration;
@@ -104,21 +104,6 @@ public class TestAsyncReplicationAdminApiWithClusters 
extends TestAsyncAdminBase
     cleanupTables(admin2, pattern);
   }
 
-  private void cleanupTables(AsyncAdmin admin, Pattern pattern) {
-    admin.listTableNames(pattern, false).whenCompleteAsync((tables, err) -> {
-      if (tables != null) {
-        tables.forEach(table -> {
-          try {
-            admin.disableTable(table).join();
-          } catch (Exception e) {
-            LOG.debug("Table: " + tableName + " already disabled, so just 
deleting it.");
-          }
-          admin.deleteTable(table).join();
-        });
-      }
-    }, ForkJoinPool.commonPool()).join();
-  }
-
   private void createTableWithDefaultConf(AsyncAdmin admin, TableName 
tableName) {
     TableDescriptorBuilder builder = 
TableDescriptorBuilder.newBuilder(tableName);
     builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));

Reply via email to