From c0e6aabf0daf0281d9874afc8b1e0ee080d052e0 Mon Sep 17 00:00:00 2001 From: Artem Ervits Date: Tue, 16 Oct 2018 15:58:45 -0400 Subject: [PATCH] HBASE-21279 Split TestAdminShell into several tests --- .../apache/hadoop/hbase/client/TestAdminShell.java | 1 + hbase-shell/src/test/ruby/hbase/admin_test.rb | 450 ------------------- hbase-shell/src/test/ruby/hbase/admin_test2.rb | 481 +++++++++++++++++++++ 3 files changed, 482 insertions(+), 450 deletions(-) create mode 100644 hbase-shell/src/test/ruby/hbase/admin_test2.rb diff --git hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java index 1835d88dc5..b449194d4b 100644 --- hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java +++ hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java @@ -36,6 +36,7 @@ public class TestAdminShell extends AbstractTestShell { @Test public void testRunShellTests() throws IOException { System.setProperty("shell.test.include", "admin_test.rb"); + System.setProperty("shell.test.include", "admin_test2.rb"); // Start all ruby tests jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); } diff --git hbase-shell/src/test/ruby/hbase/admin_test.rb hbase-shell/src/test/ruby/hbase/admin_test.rb index 1a129217a6..973474c7a7 100644 --- hbase-shell/src/test/ruby/hbase/admin_test.rb +++ hbase-shell/src/test/ruby/hbase/admin_test.rb @@ -443,454 +443,4 @@ module Hbase command(:unassign, encodedRegionName, true) end end - - # Simple administration methods tests - # rubocop:disable Metrics/ClassLength - class AdminAlterTableTest < Test::Unit::TestCase - include TestHelpers - - def setup - setup_hbase - # Create test table if it does not exist - @test_name = "hbase_shell_tests_table" - drop_test_table(@test_name) - create_test_table(@test_name) - end - - def teardown - shutdown - end - - #------------------------------------------------------------------------------- - - define_test "alter should fail with non-string table names" do - assert_raise(ArgumentError) do - command(:alter, 123, METHOD => 'delete', NAME => 'y') - end - end - - define_test "alter should fail with non-existing tables" do - assert_raise(ArgumentError) do - command(:alter, 'NOT.EXISTS', METHOD => 'delete', NAME => 'y') - end - end - - define_test "alter should not fail with enabled tables" do - command(:enable, @test_name) - command(:alter, @test_name, METHOD => 'delete', NAME => 'y') - end - - define_test "alter should be able to delete column families" do - assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) - command(:alter, @test_name, METHOD => 'delete', NAME => 'y') - command(:enable, @test_name) - assert_equal(['x:'], table(@test_name).get_all_columns.sort) - end - - define_test "alter should be able to add column families" do - assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) - command(:alter, @test_name, NAME => 'z') - command(:enable, @test_name) - assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort) - end - - define_test "alter should be able to add column families (name-only alter spec)" do - assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) - command(:alter, @test_name, 'z') - command(:enable, @test_name) - assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort) - end - - define_test 'alter should support more than one alteration in one call' do - assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) - alter_out_put = capture_stdout do - command(:alter, @test_name, { NAME => 'z' }, - { METHOD => 'delete', NAME => 'y' }, - 'MAX_FILESIZE' => 12_345_678) - end - command(:enable, @test_name) - assert_equal(1, /Updating all regions/.match(alter_out_put).size, - "HBASE-15641 - Should only perform one table - modification per alter.") - assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort) - assert_match(/12345678/, admin.describe(@test_name)) - end - - define_test 'alter should be able to set the TargetRegionSize and TargetRegionCount' do - command(:alter, @test_name, 'NORMALIZER_TARGET_REGION_COUNT' => 156) - assert_match(/156/, admin.describe(@test_name)) - command(:alter, @test_name, 'NORMALIZER_TARGET_REGION_SIZE' => 234) - assert_match(/234/, admin.describe(@test_name)) - end - - define_test 'alter should support shortcut DELETE alter specs' do - assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) - command(:alter, @test_name, 'delete' => 'y') - assert_equal(['x:'], table(@test_name).get_all_columns.sort) - end - - define_test "alter should be able to change table options" do - command(:alter, @test_name, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678) - assert_match(/12345678/, admin.describe(@test_name)) - end - - define_test "alter should be able to change table options w/o table_att" do - command(:alter, @test_name, 'MAX_FILESIZE' => 12345678) - assert_match(/12345678/, admin.describe(@test_name)) - end - - define_test "alter should be able to change coprocessor attributes" do - drop_test_table(@test_name) - create_test_table(@test_name) - - cp_key = "coprocessor" - class_name = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver" - - cp_value = "|" + class_name + "|12|arg1=1,arg2=2" - - # eval() is used to convert a string to regex - assert_no_match(eval("/" + class_name + "/"), admin.describe(@test_name)) - assert_no_match(eval("/" + cp_key + "/"), admin.describe(@test_name)) - command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value) - assert_match(eval("/" + class_name + "/"), admin.describe(@test_name)) - assert_match(eval("/" + cp_key + "\\$(\\d+)/"), admin.describe(@test_name)) - end - - define_test "alter should be able to remove a table attribute" do - drop_test_table(@test_name) - create_test_table(@test_name) - - key = "MAX_FILESIZE" - command(:alter, @test_name, 'METHOD' => 'table_att', key => 12345678) - - # eval() is used to convert a string to regex - assert_match(eval("/" + key + "/"), admin.describe(@test_name)) - - command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => key) - assert_no_match(eval("/" + key + "/"), admin.describe(@test_name)) - end - - define_test "alter should be able to remove a list of table attributes" do - drop_test_table(@test_name) - - key_1 = "TestAttr1" - key_2 = "TestAttr2" - command(:create, @test_name, { NAME => 'i'}, METADATA => { key_1 => 1, key_2 => 2 }) - - # eval() is used to convert a string to regex - assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) - assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) - - command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => [ key_1, key_2 ]) - assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) - assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) - end - - define_test "alter should be able to remove a table configuration" do - drop_test_table(@test_name) - create_test_table(@test_name) - - key = "TestConf" - command(:alter, @test_name, CONFIGURATION => {key => 1}) - - # eval() is used to convert a string to regex - assert_match(eval("/" + key + "/"), admin.describe(@test_name)) - - command(:alter, @test_name, 'METHOD' => 'table_conf_unset', 'NAME' => key) - assert_no_match(eval("/" + key + "/"), admin.describe(@test_name)) - end - - define_test "alter should be able to remove a list of table configuration" do - drop_test_table(@test_name) - - key_1 = "TestConf1" - key_2 = "TestConf2" - command(:create, @test_name, { NAME => 'i'}, CONFIGURATION => { key_1 => 1, key_2 => 2 }) - - # eval() is used to convert a string to regex - assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) - assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) - - command(:alter, @test_name, 'METHOD' => 'table_conf_unset', 'NAME' => [ key_1, key_2 ]) - assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) - assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) - end - - define_test "get_table should get a real table" do - drop_test_table(@test_name) - create_test_table(@test_name) - - table = table(@test_name) - assert_not_equal(nil, table) - table.close - end - end - # rubocop:enable Metrics/ClassLength - - # Tests for the `status` shell command - class StatusTest < Test::Unit::TestCase - include TestHelpers - - def setup - setup_hbase - # Create test table if it does not exist - @test_name = 'hbase_shell_tests_table' - drop_test_table(@test_name) - create_test_table(@test_name) - end - - def teardown - shutdown - end - - define_test 'Get replication status' do - output = capture_stdout { replication_status('replication', 'both') } - puts "Status output:\n#{output}" - assert output.include? 'SOURCE' - assert output.include? 'SINK' - end - - define_test 'Get replication source metrics information' do - output = capture_stdout { replication_status('replication', 'source') } - puts "Status output:\n#{output}" - assert output.include? 'SOURCE' - end - - define_test 'Get replication sink metrics information' do - output = capture_stdout { replication_status('replication', 'sink') } - puts "Status output:\n#{output}" - assert output.include? 'SINK' - end - - define_test 'Get simple status' do - output = capture_stdout { admin.status('simple', '') } - puts "Status output:\n#{output}" - assert output.include? 'active master' - end - - define_test 'Get detailed status' do - output = capture_stdout { admin.status('detailed', '') } - puts "Status output:\n#{output}" - # Some text which isn't in the simple output - assert output.include? 'regionsInTransition' - end - end - - # Simple administration methods tests - # rubocop:disable ClassLength - class AdminSnapshotTest < Test::Unit::TestCase - include TestHelpers - - def setup - setup_hbase - # Create test table if it does not exist - @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' - end - - def teardown - shutdown - end - - #------------------------------------------------------------------------------- - define_test "Snapshot should fail with non-string table name" do - assert_raise(ArgumentError) do - command(:snapshot, 123, 'xxx') - end - end - - define_test "Snapshot should fail with non-string snapshot name" do - assert_raise(ArgumentError) do - command(:snapshot, @test_name, 123) - end - end - - define_test "Snapshot should fail without snapshot name" do - assert_raise(ArgumentError) do - command(:snapshot, @test_name) - end - end - - define_test "Snapshot should work with string args" do - drop_test_snapshot() - command(:snapshot, @test_name, @create_test_snapshot) - list = command(:list_snapshots, @create_test_snapshot) - assert_equal(1, list.size) - end - - define_test "Snapshot should work when SKIP_FLUSH args" do - drop_test_snapshot() - command(:snapshot, @test_name, @create_test_snapshot, {SKIP_FLUSH => true}) - list = command(:list_snapshots, @create_test_snapshot) - assert_equal(1, list.size) - end - - define_test "List snapshot without any args" do - drop_test_snapshot() - command(:snapshot, @test_name, @create_test_snapshot) - list = command(:list_snapshots) - assert_equal(1, list.size) - end - - define_test "List snapshot for a non-existing snapshot" do - list = command(:list_snapshots, "xyz") - assert_equal(0, list.size) - end - - define_test "Restore snapshot without any args" do - assert_raise(ArgumentError) do - command(:restore_snapshot) - end - end - - define_test 'Restore snapshot should work' do - drop_test_snapshot - restore_table = 'test_restore_snapshot_table' - command(:create, restore_table, 'f1', 'f2') - assert_match(/f1/, admin.describe(restore_table)) - assert_match(/f2/, admin.describe(restore_table)) - command(:snapshot, restore_table, @create_test_snapshot) - command(:alter, restore_table, METHOD => 'delete', NAME => 'f1') - assert_no_match(/f1/, admin.describe(restore_table)) - assert_match(/f2/, admin.describe(restore_table)) - drop_test_table(restore_table) - command(:restore_snapshot, @create_test_snapshot) - assert_match(/f1/, admin.describe(restore_table)) - assert_match(/f2/, admin.describe(restore_table)) - drop_test_table(restore_table) - end - - define_test 'Restore snapshot should fail' do - drop_test_snapshot - restore_table = 'test_restore_snapshot_table' - command(:create, restore_table, 'f1', 'f2') - assert_match(/f1/, admin.describe(restore_table)) - assert_match(/f2/, admin.describe(restore_table)) - command(:snapshot, restore_table, @create_test_snapshot) - assert_raise(RuntimeError) do - command(:restore_snapshot, @create_test_snapshot) - end - drop_test_table(restore_table) - end - - define_test "Clone snapshot without any args" do - assert_raise(ArgumentError) do - command(:restore_snapshot) - end - end - - define_test "Clone snapshot without table name args" do - assert_raise(ArgumentError) do - command(:clone_snapshot, @create_test_snapshot) - end - end - - define_test "Clone snapshot should work" do - drop_test_snapshot() - clone_table = "test_clone_snapshot_table" - assert_match(eval("/" + "x" + "/"), admin.describe(@test_name)) - assert_match(eval("/" + "y" + "/"), admin.describe(@test_name)) - command(:snapshot, @test_name, @create_test_snapshot) - command(:clone_snapshot, @create_test_snapshot, clone_table) - assert_match(eval("/" + "x" + "/"), admin.describe(clone_table)) - assert_match(eval("/" + "y" + "/"), admin.describe(clone_table)) - drop_test_table(clone_table) - end - - define_test "Delete snapshot without any args" do - assert_raise(ArgumentError) do - admin.delete_snapshot() - end - end - - define_test "Delete snapshot should work" do - drop_test_snapshot() - command(:snapshot, @test_name, @create_test_snapshot) - list = command(:list_snapshots) - assert_equal(1, list.size) - admin.delete_snapshot(@create_test_snapshot) - list = command(:list_snapshots) - assert_equal(0, list.size) - end - - define_test "Delete all snapshots without any args" do - assert_raise(ArgumentError) do - admin.delete_all_snapshot() - end - end - - define_test "Delete all snapshots should work" do - drop_test_snapshot() - command(:snapshot, @test_name, "delete_all_snapshot1") - command(:snapshot, @test_name, "delete_all_snapshot2") - command(:snapshot, @test_name, "snapshot_delete_all_1") - command(:snapshot, @test_name, "snapshot_delete_all_2") - list = command(:list_snapshots) - assert_equal(4, list.size) - admin.delete_all_snapshot("d.*") - list = command(:list_snapshots) - assert_equal(2, list.size) - admin.delete_all_snapshot(".*") - list = command(:list_snapshots) - assert_equal(0, list.size) - end - - define_test "Delete table snapshots without any args" do - assert_raise(ArgumentError) do - admin.delete_table_snapshots() - end - end - - define_test "Delete table snapshots should work" do - drop_test_snapshot() - command(:snapshot, @test_name, "delete_table_snapshot1") - command(:snapshot, @test_name, "delete_table_snapshot2") - command(:snapshot, @test_name, "snapshot_delete_table1") - new_table = "test_delete_table_snapshots_table" - command(:create, new_table, 'f1') - command(:snapshot, new_table, "delete_table_snapshot3") - list = command(:list_snapshots) - assert_equal(4, list.size) - admin.delete_table_snapshots(@test_name, "d.*") - list = command(:list_snapshots) - assert_equal(2, list.size) - admin.delete_table_snapshots(@test_name) - list = command(:list_snapshots) - assert_equal(1, list.size) - admin.delete_table_snapshots(".*", "d.*") - list = command(:list_snapshots) - assert_equal(0, list.size) - drop_test_table(new_table) - end - - define_test "List table snapshots without any args" do - assert_raise(ArgumentError) do - command(:list_table_snapshots) - end - end - - define_test "List table snapshots should work" do - drop_test_snapshot() - command(:snapshot, @test_name, "delete_table_snapshot1") - command(:snapshot, @test_name, "delete_table_snapshot2") - command(:snapshot, @test_name, "snapshot_delete_table1") - new_table = "test_list_table_snapshots_table" - command(:create, new_table, 'f1') - command(:snapshot, new_table, "delete_table_snapshot3") - list = command(:list_table_snapshots, ".*") - assert_equal(4, list.size) - list = command(:list_table_snapshots, @test_name, "d.*") - assert_equal(2, list.size) - list = command(:list_table_snapshots, @test_name) - assert_equal(3, list.size) - admin.delete_table_snapshots(".*") - list = command(:list_table_snapshots, ".*", ".*") - assert_equal(0, list.size) - drop_test_table(new_table) - end - end - # rubocop:enable ClassLength end diff --git hbase-shell/src/test/ruby/hbase/admin_test2.rb hbase-shell/src/test/ruby/hbase/admin_test2.rb new file mode 100644 index 0000000000..792479d37b --- /dev/null +++ hbase-shell/src/test/ruby/hbase/admin_test2.rb @@ -0,0 +1,481 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'shell' +require 'stringio' +require 'hbase_constants' +require 'hbase/hbase' +require 'hbase/table' + +include HBaseConstants + +module Hbase + class AdminHelpersTest < Test::Unit::TestCase + include TestHelpers + + # Simple administration methods tests + # rubocop:disable Metrics/ClassLength + class AdminAlterTableTest < Test::Unit::TestCase + include TestHelpers + + def setup + setup_hbase + # Create test table if it does not exist + @test_name = "hbase_shell_tests_table" + drop_test_table(@test_name) + create_test_table(@test_name) + end + + def teardown + shutdown + end + + #------------------------------------------------------------------------------- + + define_test "alter should fail with non-string table names" do + assert_raise(ArgumentError) do + command(:alter, 123, METHOD => 'delete', NAME => 'y') + end + end + + define_test "alter should fail with non-existing tables" do + assert_raise(ArgumentError) do + command(:alter, 'NOT.EXISTS', METHOD => 'delete', NAME => 'y') + end + end + + define_test "alter should not fail with enabled tables" do + command(:enable, @test_name) + command(:alter, @test_name, METHOD => 'delete', NAME => 'y') + end + + define_test "alter should be able to delete column families" do + assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) + command(:alter, @test_name, METHOD => 'delete', NAME => 'y') + command(:enable, @test_name) + assert_equal(['x:'], table(@test_name).get_all_columns.sort) + end + + define_test "alter should be able to add column families" do + assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) + command(:alter, @test_name, NAME => 'z') + command(:enable, @test_name) + assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort) + end + + define_test "alter should be able to add column families (name-only alter spec)" do + assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) + command(:alter, @test_name, 'z') + command(:enable, @test_name) + assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort) + end + + define_test 'alter should support more than one alteration in one call' do + assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) + alter_out_put = capture_stdout do + command(:alter, @test_name, { NAME => 'z' }, + { METHOD => 'delete', NAME => 'y' }, + 'MAX_FILESIZE' => 12_345_678) + end + command(:enable, @test_name) + assert_equal(1, /Updating all regions/.match(alter_out_put).size, + "HBASE-15641 - Should only perform one table + modification per alter.") + assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort) + assert_match(/12345678/, admin.describe(@test_name)) + end + + define_test 'alter should be able to set the TargetRegionSize and TargetRegionCount' do + command(:alter, @test_name, 'NORMALIZER_TARGET_REGION_COUNT' => 156) + assert_match(/156/, admin.describe(@test_name)) + command(:alter, @test_name, 'NORMALIZER_TARGET_REGION_SIZE' => 234) + assert_match(/234/, admin.describe(@test_name)) + end + + define_test 'alter should support shortcut DELETE alter specs' do + assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort) + command(:alter, @test_name, 'delete' => 'y') + assert_equal(['x:'], table(@test_name).get_all_columns.sort) + end + + define_test "alter should be able to change table options" do + command(:alter, @test_name, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678) + assert_match(/12345678/, admin.describe(@test_name)) + end + + define_test "alter should be able to change table options w/o table_att" do + command(:alter, @test_name, 'MAX_FILESIZE' => 12345678) + assert_match(/12345678/, admin.describe(@test_name)) + end + + define_test "alter should be able to change coprocessor attributes" do + drop_test_table(@test_name) + create_test_table(@test_name) + + cp_key = "coprocessor" + class_name = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver" + + cp_value = "|" + class_name + "|12|arg1=1,arg2=2" + + # eval() is used to convert a string to regex + assert_no_match(eval("/" + class_name + "/"), admin.describe(@test_name)) + assert_no_match(eval("/" + cp_key + "/"), admin.describe(@test_name)) + command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value) + assert_match(eval("/" + class_name + "/"), admin.describe(@test_name)) + assert_match(eval("/" + cp_key + "\\$(\\d+)/"), admin.describe(@test_name)) + end + + define_test "alter should be able to remove a table attribute" do + drop_test_table(@test_name) + create_test_table(@test_name) + + key = "MAX_FILESIZE" + command(:alter, @test_name, 'METHOD' => 'table_att', key => 12345678) + + # eval() is used to convert a string to regex + assert_match(eval("/" + key + "/"), admin.describe(@test_name)) + + command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => key) + assert_no_match(eval("/" + key + "/"), admin.describe(@test_name)) + end + + define_test "alter should be able to remove a list of table attributes" do + drop_test_table(@test_name) + + key_1 = "TestAttr1" + key_2 = "TestAttr2" + command(:create, @test_name, { NAME => 'i'}, METADATA => { key_1 => 1, key_2 => 2 }) + + # eval() is used to convert a string to regex + assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) + assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) + + command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => [ key_1, key_2 ]) + assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) + assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) + end + + define_test "alter should be able to remove a table configuration" do + drop_test_table(@test_name) + create_test_table(@test_name) + + key = "TestConf" + command(:alter, @test_name, CONFIGURATION => {key => 1}) + + # eval() is used to convert a string to regex + assert_match(eval("/" + key + "/"), admin.describe(@test_name)) + + command(:alter, @test_name, 'METHOD' => 'table_conf_unset', 'NAME' => key) + assert_no_match(eval("/" + key + "/"), admin.describe(@test_name)) + end + + define_test "alter should be able to remove a list of table configuration" do + drop_test_table(@test_name) + + key_1 = "TestConf1" + key_2 = "TestConf2" + command(:create, @test_name, { NAME => 'i'}, CONFIGURATION => { key_1 => 1, key_2 => 2 }) + + # eval() is used to convert a string to regex + assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) + assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) + + command(:alter, @test_name, 'METHOD' => 'table_conf_unset', 'NAME' => [ key_1, key_2 ]) + assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name)) + assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name)) + end + + define_test "get_table should get a real table" do + drop_test_table(@test_name) + create_test_table(@test_name) + + table = table(@test_name) + assert_not_equal(nil, table) + table.close + end + end + # rubocop:enable Metrics/ClassLength + + # Tests for the `status` shell command + class StatusTest < Test::Unit::TestCase + include TestHelpers + + def setup + setup_hbase + # Create test table if it does not exist + @test_name = 'hbase_shell_tests_table' + drop_test_table(@test_name) + create_test_table(@test_name) + end + + def teardown + shutdown + end + + define_test 'Get replication status' do + output = capture_stdout { replication_status('replication', 'both') } + puts "Status output:\n#{output}" + assert output.include? 'SOURCE' + assert output.include? 'SINK' + end + + define_test 'Get replication source metrics information' do + output = capture_stdout { replication_status('replication', 'source') } + puts "Status output:\n#{output}" + assert output.include? 'SOURCE' + end + + define_test 'Get replication sink metrics information' do + output = capture_stdout { replication_status('replication', 'sink') } + puts "Status output:\n#{output}" + assert output.include? 'SINK' + end + + define_test 'Get simple status' do + output = capture_stdout { admin.status('simple', '') } + puts "Status output:\n#{output}" + assert output.include? 'active master' + end + + define_test 'Get detailed status' do + output = capture_stdout { admin.status('detailed', '') } + puts "Status output:\n#{output}" + # Some text which isn't in the simple output + assert output.include? 'regionsInTransition' + end + end + + # Simple administration methods tests + # rubocop:disable ClassLength + class AdminSnapshotTest < Test::Unit::TestCase + include TestHelpers + + def setup + setup_hbase + # Create test table if it does not exist + @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' + end + + def teardown + shutdown + end + + #------------------------------------------------------------------------------- + define_test "Snapshot should fail with non-string table name" do + assert_raise(ArgumentError) do + command(:snapshot, 123, 'xxx') + end + end + + define_test "Snapshot should fail with non-string snapshot name" do + assert_raise(ArgumentError) do + command(:snapshot, @test_name, 123) + end + end + + define_test "Snapshot should fail without snapshot name" do + assert_raise(ArgumentError) do + command(:snapshot, @test_name) + end + end + + define_test "Snapshot should work with string args" do + drop_test_snapshot() + command(:snapshot, @test_name, @create_test_snapshot) + list = command(:list_snapshots, @create_test_snapshot) + assert_equal(1, list.size) + end + + define_test "Snapshot should work when SKIP_FLUSH args" do + drop_test_snapshot() + command(:snapshot, @test_name, @create_test_snapshot, {SKIP_FLUSH => true}) + list = command(:list_snapshots, @create_test_snapshot) + assert_equal(1, list.size) + end + + define_test "List snapshot without any args" do + drop_test_snapshot() + command(:snapshot, @test_name, @create_test_snapshot) + list = command(:list_snapshots) + assert_equal(1, list.size) + end + + define_test "List snapshot for a non-existing snapshot" do + list = command(:list_snapshots, "xyz") + assert_equal(0, list.size) + end + + define_test "Restore snapshot without any args" do + assert_raise(ArgumentError) do + command(:restore_snapshot) + end + end + + define_test 'Restore snapshot should work' do + drop_test_snapshot + restore_table = 'test_restore_snapshot_table' + command(:create, restore_table, 'f1', 'f2') + assert_match(/f1/, admin.describe(restore_table)) + assert_match(/f2/, admin.describe(restore_table)) + command(:snapshot, restore_table, @create_test_snapshot) + command(:alter, restore_table, METHOD => 'delete', NAME => 'f1') + assert_no_match(/f1/, admin.describe(restore_table)) + assert_match(/f2/, admin.describe(restore_table)) + drop_test_table(restore_table) + command(:restore_snapshot, @create_test_snapshot) + assert_match(/f1/, admin.describe(restore_table)) + assert_match(/f2/, admin.describe(restore_table)) + drop_test_table(restore_table) + end + + define_test 'Restore snapshot should fail' do + drop_test_snapshot + restore_table = 'test_restore_snapshot_table' + command(:create, restore_table, 'f1', 'f2') + assert_match(/f1/, admin.describe(restore_table)) + assert_match(/f2/, admin.describe(restore_table)) + command(:snapshot, restore_table, @create_test_snapshot) + assert_raise(RuntimeError) do + command(:restore_snapshot, @create_test_snapshot) + end + drop_test_table(restore_table) + end + + define_test "Clone snapshot without any args" do + assert_raise(ArgumentError) do + command(:restore_snapshot) + end + end + + define_test "Clone snapshot without table name args" do + assert_raise(ArgumentError) do + command(:clone_snapshot, @create_test_snapshot) + end + end + + define_test "Clone snapshot should work" do + drop_test_snapshot() + clone_table = "test_clone_snapshot_table" + assert_match(eval("/" + "x" + "/"), admin.describe(@test_name)) + assert_match(eval("/" + "y" + "/"), admin.describe(@test_name)) + command(:snapshot, @test_name, @create_test_snapshot) + command(:clone_snapshot, @create_test_snapshot, clone_table) + assert_match(eval("/" + "x" + "/"), admin.describe(clone_table)) + assert_match(eval("/" + "y" + "/"), admin.describe(clone_table)) + drop_test_table(clone_table) + end + + define_test "Delete snapshot without any args" do + assert_raise(ArgumentError) do + admin.delete_snapshot() + end + end + + define_test "Delete snapshot should work" do + drop_test_snapshot() + command(:snapshot, @test_name, @create_test_snapshot) + list = command(:list_snapshots) + assert_equal(1, list.size) + admin.delete_snapshot(@create_test_snapshot) + list = command(:list_snapshots) + assert_equal(0, list.size) + end + + define_test "Delete all snapshots without any args" do + assert_raise(ArgumentError) do + admin.delete_all_snapshot() + end + end + + define_test "Delete all snapshots should work" do + drop_test_snapshot() + command(:snapshot, @test_name, "delete_all_snapshot1") + command(:snapshot, @test_name, "delete_all_snapshot2") + command(:snapshot, @test_name, "snapshot_delete_all_1") + command(:snapshot, @test_name, "snapshot_delete_all_2") + list = command(:list_snapshots) + assert_equal(4, list.size) + admin.delete_all_snapshot("d.*") + list = command(:list_snapshots) + assert_equal(2, list.size) + admin.delete_all_snapshot(".*") + list = command(:list_snapshots) + assert_equal(0, list.size) + end + + define_test "Delete table snapshots without any args" do + assert_raise(ArgumentError) do + admin.delete_table_snapshots() + end + end + + define_test "Delete table snapshots should work" do + drop_test_snapshot() + command(:snapshot, @test_name, "delete_table_snapshot1") + command(:snapshot, @test_name, "delete_table_snapshot2") + command(:snapshot, @test_name, "snapshot_delete_table1") + new_table = "test_delete_table_snapshots_table" + command(:create, new_table, 'f1') + command(:snapshot, new_table, "delete_table_snapshot3") + list = command(:list_snapshots) + assert_equal(4, list.size) + admin.delete_table_snapshots(@test_name, "d.*") + list = command(:list_snapshots) + assert_equal(2, list.size) + admin.delete_table_snapshots(@test_name) + list = command(:list_snapshots) + assert_equal(1, list.size) + admin.delete_table_snapshots(".*", "d.*") + list = command(:list_snapshots) + assert_equal(0, list.size) + drop_test_table(new_table) + end + + define_test "List table snapshots without any args" do + assert_raise(ArgumentError) do + command(:list_table_snapshots) + end + end + + define_test "List table snapshots should work" do + drop_test_snapshot() + command(:snapshot, @test_name, "delete_table_snapshot1") + command(:snapshot, @test_name, "delete_table_snapshot2") + command(:snapshot, @test_name, "snapshot_delete_table1") + new_table = "test_list_table_snapshots_table" + command(:create, new_table, 'f1') + command(:snapshot, new_table, "delete_table_snapshot3") + list = command(:list_table_snapshots, ".*") + assert_equal(4, list.size) + list = command(:list_table_snapshots, @test_name, "d.*") + assert_equal(2, list.size) + list = command(:list_table_snapshots, @test_name) + assert_equal(3, list.size) + admin.delete_table_snapshots(".*") + list = command(:list_table_snapshots, ".*", ".*") + assert_equal(0, list.size) + drop_test_table(new_table) + end + end + # rubocop:enable ClassLength +end -- 2.16.2