From 6ff38e37df2ea2a25dca351a1e3d6d02e571d553 Mon Sep 17 00:00:00 2001 From: Thoralf Gutierrez Date: Tue, 26 Sep 2017 07:51:49 -0700 Subject: [PATCH 1/1] HBASE-18842 Fix unknown namespace message in clone_snapshot --- .../src/main/ruby/shell/commands/clone_snapshot.rb | 4 ++ hbase-shell/src/test/ruby/shell/commands_test.rb | 45 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb index 6d9c5ded2e..8f0b35b39e 100644 --- a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb @@ -47,6 +47,10 @@ EOF tableName = args[1] raise "Table already exists: #{tableName}!" end + if cause.is_a?(org.apache.hadoop.hbase.NamespaceNotFoundException) + namespace_name = args[1].split(':')[0] + raise "Unknown namespace: #{namespace_name}!" + end end end end diff --git a/hbase-shell/src/test/ruby/shell/commands_test.rb b/hbase-shell/src/test/ruby/shell/commands_test.rb index 9fa291ae1e..6f86a3730e 100644 --- a/hbase-shell/src/test/ruby/shell/commands_test.rb +++ b/hbase-shell/src/test/ruby/shell/commands_test.rb @@ -32,3 +32,48 @@ class ShellCommandsTest < Test::Unit::TestCase end end end + +## +# Tests commands from the point of view of the shell to validate +# that the error messages returned to the user are correct + +class ShellCloneSnapshotTest < Test::Unit::TestCase + include Hbase::TestHelpers + + def setup + setup_hbase + @shell.interactive = false + # Create test table + @test_name = 'hbase_shell_tests_table' + drop_test_table(@test_name) + create_test_table(@test_name) + # Test snapshot name + @create_test_snapshot = 'hbase_shell_tests_snapshot' + drop_test_snapshot + end + + def teardown + drop_test_table(@test_name) + drop_test_snapshot + shutdown + end + + define_test 'Clone snapshot with table that already exists' do + existing_table = 'existing_table' + create_test_table(existing_table) + admin.snapshot(@test_name, @create_test_snapshot) + error = assert_raise(RuntimeError) do + @shell.command(:clone_snapshot, @create_test_snapshot, existing_table) + end + assert_match(/Table already exists: existing_table!/, error.message) + end + + define_test 'Clone snapshot with unknown namespace' do + clone_table = 'does_not_exist:test_clone_snapshot_table' + admin.snapshot(@test_name, @create_test_snapshot) + error = assert_raise(RuntimeError) do + @shell.command(:clone_snapshot, @create_test_snapshot, clone_table) + end + assert_match(/Unknown namespace: does_not_exist!/, error.message) + end +end -- 2.13.5 (Apple Git-94)