Skip to content
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 @@ -35,5 +35,4 @@ public static boolean rsGroupHasOnlineServer(MasterServices master, RSGroupInfo
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,34 @@
package org.apache.hadoop.hbase.rsgroup;

import static java.lang.Thread.sleep;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test enable RSGroup
*/
@Category({ MediumTests.class })
public class TestEnableRSGroups {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestEnableRSGroups.class);
public abstract class EnableRSGroupsTestBase {

protected static final Logger LOG = LoggerFactory.getLogger(TestEnableRSGroups.class);
protected static final Logger LOG = LoggerFactory.getLogger(EnableRSGroupsTestBase.class);

private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
final Configuration conf = TEST_UTIL.getConfiguration();
conf.setBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, true);
TEST_UTIL.startMiniCluster(5);
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
LOG.info("to stop miniCluster");
TEST_UTIL.shutdownMiniCluster();
Expand Down Expand Up @@ -91,5 +79,4 @@ public void testEnableRSGroup() throws IOException, InterruptedException {

assertTrue(loadBalancer.isOnline());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,34 @@
*/
package org.apache.hadoop.hbase.rsgroup;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.constraint.ConstraintException;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category(MediumTests.class)
@Tag(MediumTests.TAG)
public class TestRSGroupConfig extends TestRSGroupsBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRSGroupConfig.class);

@Rule
public TestName name = new TestName();

protected static final Logger LOG = LoggerFactory.getLogger(TestRSGroupConfig.class);

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TestRSGroupsBase.setUpTestBeforeClass();
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
TestRSGroupsBase.tearDownAfterClass();
}
Expand All @@ -65,8 +55,8 @@ public void testSetDefaultGroupConfiguration() {
}

@Test
public void testSetNonDefaultGroupConfiguration() throws IOException {
String group = getGroupName(name.getMethodName());
public void testSetNonDefaultGroupConfiguration(TestInfo testInfo) throws IOException {
String group = getGroupName(testInfo.getTestMethod().get().getName());
rsGroupAdmin.addRSGroup(group);
testSetConfiguration(group);
rsGroupAdmin.removeRSGroup(group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,41 @@
*/
package org.apache.hadoop.hbase.rsgroup;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManagerImpl.RSGroupMappingScript;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ SmallTests.class })
@Tag(SmallTests.TAG)
public class TestRSGroupMappingScript {

private static final Logger LOG = LoggerFactory.getLogger(TestRSGroupMappingScript.class);
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRSGroupMappingScript.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private File script;

@BeforeClass
@BeforeAll
public static void setupScript() throws Exception {
String currentDir = new File("").getAbsolutePath();
UTIL.getConfiguration().set(RSGroupMappingScript.RS_GROUP_MAPPING_SCRIPT,
currentDir + "/rsgroup_table_mapping.sh");
}

@Before
@BeforeEach
public void setup() throws Exception {
script = new File(UTIL.getConfiguration().get(RSGroupMappingScript.RS_GROUP_MAPPING_SCRIPT));
if (!script.createNewFile()) {
Expand Down Expand Up @@ -97,19 +93,19 @@ public void testScript() throws Exception {
TableName testNamespace = TableName.valueOf("test", "should_be_in_test");
String rsgroup =
script.getRSGroup(testNamespace.getNamespaceAsString(), testNamespace.getQualifierAsString());
Assert.assertEquals("test", rsgroup);
assertEquals("test", rsgroup);

TableName otherName = TableName.valueOf("whatever", "oh_foo_should_be_in_other");
rsgroup = script.getRSGroup(otherName.getNamespaceAsString(), otherName.getQualifierAsString());
Assert.assertEquals("other", rsgroup);
assertEquals("other", rsgroup);

TableName defaultName = TableName.valueOf("nono", "should_be_in_default");
rsgroup =
script.getRSGroup(defaultName.getNamespaceAsString(), defaultName.getQualifierAsString());
Assert.assertEquals("default", rsgroup);
assertEquals("default", rsgroup);
}

@After
@AfterEach
public void teardown() throws Exception {
if (script.exists()) {
script.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
*/
package org.apache.hadoop.hbase.rsgroup;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableExistsException;
Expand All @@ -49,44 +48,39 @@
import org.apache.hadoop.hbase.quotas.QuotaUtil;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.com.google.common.collect.Sets;

@Category({ MediumTests.class })
@Tag(MediumTests.TAG)
public class TestRSGroupsAdmin1 extends TestRSGroupsBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRSGroupsAdmin1.class);

protected static final Logger LOG = LoggerFactory.getLogger(TestRSGroupsAdmin1.class);

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
setUpTestBeforeClass();
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
tearDownAfterClass();
}

@Before
public void beforeMethod() throws Exception {
setUpBeforeMethod();
@BeforeEach
public void beforeMethod(TestInfo testInfo) throws Exception {
setUpBeforeMethod(testInfo);
}

@After
@AfterEach
public void afterMethod() throws Exception {
tearDownAfterMethod();
}
Expand Down Expand Up @@ -224,7 +218,7 @@ public void testFailRemoveGroup() throws IOException, InterruptedException {
rsGroupAdmin.moveServers(barGroup.getServers(), RSGroupInfo.DEFAULT_GROUP);
rsGroupAdmin.removeRSGroup(barGroup.getName());

Assert.assertEquals(initNumGroups, rsGroupAdmin.listRSGroups().size());
assertEquals(initNumGroups, rsGroupAdmin.listRSGroups().size());
}

@Test
Expand Down Expand Up @@ -263,11 +257,9 @@ public boolean evaluate() throws Exception {
rsGroupAdmin.moveTables(Sets.newHashSet(tableNameA, tableNameB), newGroup.getName());

// verify group change
Assert.assertEquals(newGroup.getName(),
rsGroupAdmin.getRSGroupInfoOfTable(tableNameA).getName());
assertEquals(newGroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tableNameA).getName());

Assert.assertEquals(newGroup.getName(),
rsGroupAdmin.getRSGroupInfoOfTable(tableNameB).getName());
assertEquals(newGroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tableNameB).getName());

// verify tables' not exist in old group
Set<TableName> DefaultTables =
Expand Down Expand Up @@ -308,8 +300,7 @@ public boolean evaluate() throws Exception {
rsGroupAdmin.moveTables(Sets.newHashSet(tableName), newGroup.getName());

// verify group change
Assert.assertEquals(newGroup.getName(),
rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName());
assertEquals(newGroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName());

TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
Expand All @@ -330,13 +321,12 @@ public boolean evaluate() throws Exception {
// test truncate
admin.disableTable(tableName);
admin.truncateTable(tableName, true);
Assert.assertEquals(1, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size());
Assert.assertEquals(tableName,
rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().first());
assertEquals(1, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size());
assertEquals(tableName, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().first());

// verify removed table is removed from group
TEST_UTIL.deleteTable(tableName);
Assert.assertEquals(0, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size());
assertEquals(0, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size());

assertTrue(observer.preMoveTablesCalled);
assertTrue(observer.postMoveTablesCalled);
Expand Down Expand Up @@ -371,8 +361,7 @@ public boolean evaluate() throws Exception {
rsGroupAdmin.moveTables(Sets.newHashSet(tableName), newGroup.getName());

// verify group change
Assert.assertEquals(newGroup.getName(),
rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName());
assertEquals(newGroup.getName(), rsGroupAdmin.getRSGroupInfoOfTable(tableName).getName());
}

@Test
Expand Down Expand Up @@ -427,13 +416,13 @@ public void testRSGroupListDoesNotContainFailedTableCreation() throws Exception

try {
admin.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 6);
Assert.fail("Creation table should fail because of quota violation.");
fail("Creation table should fail because of quota violation.");
} catch (Exception exp) {
assertTrue(exp instanceof IOException);
constraintViolated = true;
} finally {
assertTrue("Constraint not violated for table " + tableDescTwo.getTableName(),
constraintViolated);
assertTrue(constraintViolated,
"Constraint not violated for table " + tableDescTwo.getTableName());
}
List<RSGroupInfo> rsGroupInfoList = rsGroupAdmin.listRSGroups();
boolean foundTable2 = false;
Expand All @@ -446,8 +435,8 @@ public void testRSGroupListDoesNotContainFailedTableCreation() throws Exception
foundTable1 = true;
}
}
assertFalse("Found table2 in rsgroup list.", foundTable2);
assertTrue("Did not find table1 in rsgroup list", foundTable1);
assertFalse(foundTable2, "Found table2 in rsgroup list.");
assertTrue(foundTable1, "Did not find table1 in rsgroup list");

TEST_UTIL.deleteTable(tableDescOne.getTableName());
admin.deleteNamespace(nspDesc.getName());
Expand Down Expand Up @@ -480,7 +469,7 @@ public boolean evaluate() throws Exception {
});
SortedSet<TableName> tables =
rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getTables();
assertTrue("Table 't1' must be in 'default' rsgroup", tables.contains(tn1));
assertTrue(tables.contains(tn1), "Table 't1' must be in 'default' rsgroup");

// Cleanup
TEST_UTIL.deleteTable(tn1);
Expand Down
Loading