You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zg...@apache.org on 2019/01/30 08:00:28 UTC

[hbase] branch branch-2 updated: HBASE-21699 Fixed create table failed when using SPLITS_FILE => 'splits.txt'

This is an automated email from the ASF dual-hosted git repository.

zghao pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 69c331e  HBASE-21699 Fixed create table failed when using SPLITS_FILE => 'splits.txt'
69c331e is described below

commit 69c331efed84a6fa485ee73168eb3659df116197
Author: wanghuan <wa...@seagroup.com>
AuthorDate: Wed Jan 9 13:41:13 2019 +0800

    HBASE-21699 Fixed create table failed when using SPLITS_FILE => 'splits.txt'
    
    Signed-off-by: Guanghao Zhang <zg...@apache.org>
---
 .../org/apache/hadoop/hbase/HTableDescriptor.java  |  2 +-
 .../apache/hadoop/hbase/TestHTableDescriptor.java  |  8 ++++-
 .../hadoop/hbase/client/TestFromClientSide.java    |  2 +-
 hbase-shell/src/test/ruby/hbase/table_test.rb      | 40 ++++++++++++++++------
 hbase-shell/src/test/ruby/test_helper.rb           | 16 +++++----
 5 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
index db62391..896ec94 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java
@@ -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;
   }
 
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
index 7b230eb..c043a10 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/TestHTableDescriptor.java
@@ -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",
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
index 90c74f2..d458218 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
@@ -6746,4 +6746,4 @@ public class TestFromClientSide {
 
     TEST_UTIL.getAdmin().modifyTable(newDesc);
   }
-}
+}
\ No newline at end of file
diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb
index b3343e2..e2645d8 100644
--- a/hbase-shell/src/test/ruby/hbase/table_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/table_test.rb
@@ -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 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.
+    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
diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb
index f72a1c6..78fba7a 100644
--- a/hbase-shell/src/test/ruby/test_helper.rb
+++ b/hbase-shell/src/test/ruby/test_helper.rb
@@ -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)