Skip to content

Commit

Permalink
HBASE-24907 Turn off the balancer when test region admin api (#2278)
Browse files Browse the repository at this point in the history
Signed-off-by: meiyi <myimeiyi@gmail.com>
  • Loading branch information
infraio committed Aug 20, 2020
1 parent 0b4c9f1 commit 3f10933
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,27 @@ public void setUp() throws Exception {

@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand All @@ -53,6 +54,8 @@
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -39,6 +40,8 @@
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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
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;
Expand Down Expand Up @@ -104,21 +104,6 @@ public void tearDown() throws Exception {
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));
Expand Down

0 comments on commit 3f10933

Please sign in to comment.