HBASE-21699 Fixed create table failed when using SPLITS_FILE => 'splits.txt'

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
wanghuan 2019-01-09 13:41:13 +08:00 committed by Guanghao Zhang
parent f997252344
commit 16c7f5dac9
5 changed files with 48 additions and 20 deletions

View File

@ -192,7 +192,7 @@ public class HTableDescriptor implements TableDescriptor, Comparable<HTableDescr
* @param value The value. If null, removes the setting.
*/
public HTableDescriptor setValue(String key, String value) {
getDelegateeForModification().setValue(Bytes.toBytes(key), Bytes.toBytes(value));
getDelegateeForModification().setValue(key, value);
return this;
}

View File

@ -175,7 +175,7 @@ public class TestHTableDescriptor {
* @throws Exception
*/
@Test
public void testRemoveString() throws Exception {
public void testAddGetRemoveString() throws Exception {
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
String key = "Some";
String value = "value";
@ -183,6 +183,12 @@ public class TestHTableDescriptor {
assertEquals(value, desc.getValue(key));
desc.remove(key);
assertEquals(null, desc.getValue(key));
String keyShouldNotNull = "Some2";
String valueIsNull = null;
desc.setValue(keyShouldNotNull, valueIsNull);
assertEquals(valueIsNull, desc.getValue(keyShouldNotNull));
desc.remove(keyShouldNotNull);
assertEquals(null, desc.getValue(keyShouldNotNull));
}
String legalTableNames[] = { "foo", "with-dash_under.dot", "_under_start_ok",

View File

@ -6746,4 +6746,4 @@ public class TestFromClientSide {
TEST_UTIL.getAdmin().modifyTable(newDesc);
}
}
}

View File

@ -752,20 +752,38 @@ module Hbase
end
end
define_test "Split count for a table" do
@testTableName = "tableWithSplits"
create_test_table_with_splits(@testTableName, SPLITS => ['10', '20', '30', '40'])
@table = table(@testTableName)
splits = @table._get_splits_internal()
#Total splits is 5 but here count is 4 as we ignore implicit empty split.
define_test 'Split count for a table' do
@test_table_name = 'table_with_splits'
create_test_table_with_splits(@test_table_name, SPLITS => %w[10 20 30 40])
@table = table(@test_table_name)
splits = @table._get_splits_internal
# Total splits is 5 but here count is 4 as we ignore implicit empty split.
assert_equal(4, splits.size)
assert_equal(["10", "20", "30", "40"], splits)
drop_test_table(@testTableName)
assert_equal(%w[10 20 30 40], splits)
drop_test_table(@test_table_name)
end
define_test "Split count for a empty table" do
splits = @test_table._get_splits_internal()
#Empty split should not be part of this array.
define_test 'Split count for a table by file' do
@test_table_name = 'table_with_splits_file'
@splits_file = 'target/generated-test-sources/splits.txt'
File.exist?(@splits_file) && File.delete(@splits_file)
file = File.new(@splits_file, 'w')
%w[10 20 30 40].each { |item| file.puts item }
file.close
create_test_table_with_splits_file(@test_table_name,
SPLITS_FILE => @splits_file)
@table = table(@test_table_name)
splits = @table._get_splits_internal
# Total splits is 5 but here count is 4 as we ignore implicit empty split.
assert_equal(4, splits.size)
assert_equal(%w[10 20 30 40], splits)
drop_test_table(@test_table_name)
File.delete(@splits_file)
end
define_test 'Split count for a empty table' do
splits = @test_table._get_splits_internal
# Empty split should not be part of this array.
assert_equal(0, splits.size)
assert_equal([], splits)
end

View File

@ -102,14 +102,18 @@ module Hbase
def create_test_table_with_splits(name, splits)
# Create the table if needed
unless admin.exists?(name)
command(:create, name, 'f1', splits)
end
command(:create, name, 'f1', splits) unless admin.exists?(name)
# Enable the table if needed
unless admin.enabled?(name)
admin.enable(name)
end
admin.enable(name) unless admin.enabled?(name)
end
def create_test_table_with_splits_file(name, splits_file)
# Create the table if needed
command(:create, name, 'f1', splits_file) unless admin.exists?(name)
# Enable the table if needed
admin.enable(name) unless admin.enabled?(name)
end
def create_test_table_with_region_replicas(name, num_of_replicas, splits)