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:
parent
529eb47281
commit
69c331efed
|
@ -191,7 +191,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -752,19 +752,37 @@ 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()
|
||||
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()
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue