Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-24907 Turn off the balancer when test region admin api #2278

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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