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
f997252344
commit
16c7f5dac9
|
@ -192,7 +192,7 @@ public class HTableDescriptor implements TableDescriptor, Comparable<HTableDescr
|
||||||
* @param value The value. If null, removes the setting.
|
* @param value The value. If null, removes the setting.
|
||||||
*/
|
*/
|
||||||
public HTableDescriptor setValue(String key, String value) {
|
public HTableDescriptor setValue(String key, String value) {
|
||||||
getDelegateeForModification().setValue(Bytes.toBytes(key), Bytes.toBytes(value));
|
getDelegateeForModification().setValue(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class TestHTableDescriptor {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveString() throws Exception {
|
public void testAddGetRemoveString() throws Exception {
|
||||||
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
|
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
|
||||||
String key = "Some";
|
String key = "Some";
|
||||||
String value = "value";
|
String value = "value";
|
||||||
|
@ -183,6 +183,12 @@ public class TestHTableDescriptor {
|
||||||
assertEquals(value, desc.getValue(key));
|
assertEquals(value, desc.getValue(key));
|
||||||
desc.remove(key);
|
desc.remove(key);
|
||||||
assertEquals(null, desc.getValue(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",
|
String legalTableNames[] = { "foo", "with-dash_under.dot", "_under_start_ok",
|
||||||
|
|
|
@ -752,19 +752,37 @@ module Hbase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
define_test "Split count for a table" do
|
define_test 'Split count for a table' do
|
||||||
@testTableName = "tableWithSplits"
|
@test_table_name = 'table_with_splits'
|
||||||
create_test_table_with_splits(@testTableName, SPLITS => ['10', '20', '30', '40'])
|
create_test_table_with_splits(@test_table_name, SPLITS => %w[10 20 30 40])
|
||||||
@table = table(@testTableName)
|
@table = table(@test_table_name)
|
||||||
splits = @table._get_splits_internal()
|
splits = @table._get_splits_internal
|
||||||
# Total splits is 5 but here count is 4 as we ignore implicit empty split.
|
# Total splits is 5 but here count is 4 as we ignore implicit empty split.
|
||||||
assert_equal(4, splits.size)
|
assert_equal(4, splits.size)
|
||||||
assert_equal(["10", "20", "30", "40"], splits)
|
assert_equal(%w[10 20 30 40], splits)
|
||||||
drop_test_table(@testTableName)
|
drop_test_table(@test_table_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
define_test "Split count for a empty table" do
|
define_test 'Split count for a table by file' do
|
||||||
splits = @test_table._get_splits_internal()
|
@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.
|
# Empty split should not be part of this array.
|
||||||
assert_equal(0, splits.size)
|
assert_equal(0, splits.size)
|
||||||
assert_equal([], splits)
|
assert_equal([], splits)
|
||||||
|
|
|
@ -102,14 +102,18 @@ module Hbase
|
||||||
|
|
||||||
def create_test_table_with_splits(name, splits)
|
def create_test_table_with_splits(name, splits)
|
||||||
# Create the table if needed
|
# Create the table if needed
|
||||||
unless admin.exists?(name)
|
command(:create, name, 'f1', splits) unless admin.exists?(name)
|
||||||
command(:create, name, 'f1', splits)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Enable the table if needed
|
# Enable the table if needed
|
||||||
unless admin.enabled?(name)
|
admin.enable(name) unless admin.enabled?(name)
|
||||||
admin.enable(name)
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def create_test_table_with_region_replicas(name, num_of_replicas, splits)
|
def create_test_table_with_region_replicas(name, num_of_replicas, splits)
|
||||||
|
|
Loading…
Reference in New Issue