From 9ea7ab849cc7fa2046a08ccdb49d8ff52d612cee Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Fri, 7 Aug 2015 11:14:38 -0700 Subject: [PATCH] HBASE-14105 Add shell tests for Snapshot Signed-off-by: Andrew Purtell --- hbase-shell/src/test/ruby/hbase/admin_test.rb | 203 ++++++++++++++++++ hbase-shell/src/test/ruby/test_helper.rb | 8 + 2 files changed, 211 insertions(+) diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb index b643890dbbe..0a1a92ea976 100644 --- a/hbase-shell/src/test/ruby/hbase/admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb @@ -385,4 +385,207 @@ module Hbase replication_status("replication", "sink") end end + +# Simple administration methods tests + 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 snapshot name" do + assert_raise(NoMethodError) do + admin.snapshot(123, 'xxx') + end + end + + define_test "Snapshot should fail with non-string table name" do + assert_raise(NoMethodError) do + admin.snapshot(@create_test_snapshot, 123) + end + end + + define_test "Snapshot should fail without table name" do + assert_raise(ArgumentError) do + admin.snapshot("hbase_create_test_snapshot") + end + end + + define_test "Snapshot should work with string args" do + drop_test_snapshot() + admin.snapshot(@test_name, @create_test_snapshot) + list = admin.list_snapshot(@create_test_snapshot) + assert_equal(1, list.size) + end + + define_test "Snapshot should work when SKIP_FLUSH args" do + drop_test_snapshot() + admin.snapshot(@test_name, @create_test_snapshot, {SKIP_FLUSH => true}) + list = admin.list_snapshot(@create_test_snapshot) + assert_equal(1, list.size) + end + + define_test "List snapshot without any args" do + drop_test_snapshot() + admin.snapshot(@test_name, @create_test_snapshot) + list = admin.list_snapshot() + assert_equal(1, list.size) + end + + define_test "List snapshot for a non-existing snapshot" do + list = admin.list_snapshot("xyz") + assert_equal(0, list.size) + end + + define_test "Restore snapshot without any args" do + assert_raise(ArgumentError) do + admin.restore_snapshot() + end + end + + define_test "Restore snapshot should work" do + drop_test_snapshot() + restore_table = "test_restore_snapshot_table" + admin.create(restore_table, 'f1', 'f2') + assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table)) + assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table)) + admin.snapshot(restore_table, @create_test_snapshot) + admin.alter(restore_table, true, METHOD => 'delete', NAME => 'f1') + assert_no_match(eval("/" + "f1" + "/"), admin.describe(restore_table)) + assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table)) + drop_test_table(restore_table) + admin.restore_snapshot(@create_test_snapshot) + assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table)) + assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table)) + drop_test_table(restore_table) + end + + define_test "Clone snapshot without any args" do + assert_raise(ArgumentError) do + admin.restore_snapshot() + end + end + + define_test "Clone snapshot without table name args" do + assert_raise(ArgumentError) do + admin.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)) + admin.snapshot(@test_name, @create_test_snapshot) + admin.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() + admin.snapshot(@test_name, @create_test_snapshot) + list = admin.list_snapshot() + assert_equal(1, list.size) + admin.delete_snapshot(@create_test_snapshot) + list = admin.list_snapshot() + 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() + admin.snapshot(@test_name, "delete_all_snapshot1") + admin.snapshot(@test_name, "delete_all_snapshot2") + admin.snapshot(@test_name, "snapshot_delete_all_1") + admin.snapshot(@test_name, "snapshot_delete_all_2") + list = admin.list_snapshot() + assert_equal(4, list.size) + admin.delete_all_snapshot("d.*") + list = admin.list_snapshot() + assert_equal(2, list.size) + admin.delete_all_snapshot(".*") + list = admin.list_snapshot() + 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() + admin.snapshot(@test_name, "delete_table_snapshot1") + admin.snapshot(@test_name, "delete_table_snapshot2") + admin.snapshot(@test_name, "snapshot_delete_table1") + new_table = "test_delete_table_snapshots_table" + admin.create(new_table, 'f1') + admin.snapshot(new_table, "delete_table_snapshot3") + list = admin.list_snapshot() + assert_equal(4, list.size) + admin.delete_table_snapshots(@test_name, "d.*") + list = admin.list_snapshot() + assert_equal(2, list.size) + admin.delete_table_snapshots(@test_name) + list = admin.list_snapshot() + assert_equal(1, list.size) + admin.delete_table_snapshots(".*", "d.*") + list = admin.list_snapshot() + assert_equal(0, list.size) + drop_test_table(new_table) + end + + define_test "List table snapshots without any args" do + assert_raise(ArgumentError) do + admin.list_table_snapshots() + end + end + + define_test "List table snapshots should work" do + drop_test_snapshot() + admin.snapshot(@test_name, "delete_table_snapshot1") + admin.snapshot(@test_name, "delete_table_snapshot2") + admin.snapshot(@test_name, "snapshot_delete_table1") + new_table = "test_list_table_snapshots_table" + admin.create(new_table, 'f1') + admin.snapshot(new_table, "delete_table_snapshot3") + list = admin.list_table_snapshots(".*") + assert_equal(4, list.size) + list = admin.list_table_snapshots(@test_name, "d.*") + assert_equal(2, list.size) + list = admin.list_table_snapshots(@test_name) + assert_equal(3, list.size) + admin.delete_table_snapshots(".*") + list = admin.list_table_snapshots(".*", ".*") + assert_equal(0, list.size) + drop_test_table(new_table) + end + end end diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb index 80eb4f56a3b..67bbb14fe60 100644 --- a/hbase-shell/src/test/ruby/test_helper.rb +++ b/hbase-shell/src/test/ruby/test_helper.rb @@ -114,6 +114,14 @@ module Hbase def replication_status(format,type) return admin.status(format,type) end + + def drop_test_snapshot() + begin + admin.delete_all_snapshot(".*") + rescue => e + puts "IGNORING DELETE ALL SNAPSHOT ERROR: #{e}" + end + end end end