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 @@ -541,7 +541,7 @@ public TableDescriptorBuilder setReplicationScope(int scope) {
}

public TableDescriptorBuilder setRegionServerGroup(String group) {
desc.setValue(RSGROUP_KEY, new Bytes(Bytes.toBytes(group)));
desc.setValue(RSGROUP_KEY, group);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -27,6 +28,7 @@
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.BuilderStyleTest;
Expand Down Expand Up @@ -291,4 +293,14 @@ public void testStringCustomizedValues() {
"{TABLE_ATTRIBUTES => {DURABILITY => 'ASYNC_WAL'}}, {NAME => 'cf', BLOCKSIZE => '1000'}",
htd.toStringCustomizedValues());
}

@Test
public void testGetSetRegionServerGroup() {
String groupName = name.getMethodName();
TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
.setRegionServerGroup(groupName).build();
assertEquals(htd.getValue(RSGroupInfo.TABLE_DESC_PROP_GROUP), groupName);
htd = TableDescriptorBuilder.newBuilder(htd).setRegionServerGroup(null).build();
assertNull(htd.getValue(RSGroupInfo.TABLE_DESC_PROP_GROUP));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,39 @@ public void testRenameRSGroupConstraints() throws Exception {
}

}

@Test
public void testTableConstraint() throws Exception {
String prefix = name.getMethodName();
String ns = prefix + "_ns";
TableName tableName = TableName.valueOf(ns + ":" + "t");
String nsGroup = prefix + "_nsg";
String tableGroup = prefix + "_tg";
addGroup(nsGroup, 1);
addGroup(tableGroup, 1);
ADMIN.createNamespace(NamespaceDescriptor.create(ns).build());
TEST_UTIL.createTable(tableName, "C");
TEST_UTIL.waitTableAvailable(tableName);
assertEquals(ADMIN.getRSGroup(tableName).getName(), RSGroupInfo.DEFAULT_GROUP);
// set table's rsgroup
TableDescriptor td = TableDescriptorBuilder.newBuilder(ADMIN.getDescriptor(tableName))
.setRegionServerGroup(tableGroup).build();
ADMIN.modifyTable(td);
TEST_UTIL.waitUntilNoRegionsInTransition();
assertEquals(ADMIN.getRSGroup(tableName).getName(), tableGroup);
// set namespace's rsgroup
NamespaceDescriptor nd = NamespaceDescriptor.create(ADMIN.getNamespaceDescriptor(ns))
.addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, nsGroup).build();
ADMIN.modifyNamespace(nd);
assertEquals(ADMIN.getRSGroup(tableName).getName(), tableGroup);
// clear table's rsgroup
td = TableDescriptorBuilder.newBuilder(ADMIN.getDescriptor(tableName))
.setRegionServerGroup(null).build();
ADMIN.modifyTable(td);
TEST_UTIL.waitUntilNoRegionsInTransition();
assertEquals(ADMIN.getRSGroup(tableName).getName(), nsGroup);

TEST_UTIL.deleteTable(tableName);
ADMIN.deleteNamespace(ns);
}
}
18 changes: 18 additions & 0 deletions hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

module Hbase
class RSGroupShellTest < Test::Unit::TestCase
include HBaseConstants
def setup
@hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
@shell = Shell::Shell.new(@hbase)
Expand Down Expand Up @@ -191,5 +192,22 @@ def remove_rsgroup(group_name)

remove_rsgroup(group_name)
end

define_test 'Test set/unset rsgroup of table' do
group_name = 'test_group'
table_name = 'test_table'
add_rsgroup_and_move_one_server(group_name)
@shell.command('create', table_name, 'f')

@shell.command(:alter, table_name, CONFIGURATION => { 'hbase.rsgroup.name' => group_name })
assert_equal(1, @admin.listTablesInRSGroup(group_name).count)

@shell.command(:alter, table_name, METHOD => 'table_conf_unset', NAME => 'hbase.rsgroup.name')
assert_equal(0, @admin.listTablesInRSGroup(group_name).count)

@shell.command(:disable, table_name)
@shell.command(:drop, table_name)
remove_rsgroup(group_name)
end
end
end