hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [1/5] hbase git commit: HBASE-14105 Add shell tests for Snapshot
Date Fri, 07 Aug 2015 18:14:22 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 0dd330b17 -> 725231c39
  refs/heads/branch-1 b194052ec -> 832a61513
  refs/heads/branch-1.0 0ac0e934e -> 5d802f35c
  refs/heads/branch-1.1 66e305810 -> 007fa52fc
  refs/heads/branch-1.2 0ec323ffa -> bb1407d94


HBASE-14105 Add shell tests for Snapshot

Signed-off-by: Andrew Purtell <apurtell@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/832a6151
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/832a6151
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/832a6151

Branch: refs/heads/branch-1
Commit: 832a61513b5ae9a65f6be27f5f83d03a006351be
Parents: b194052
Author: Ashish Singhi <ashish.singhi@huawei.com>
Authored: Fri Aug 7 10:00:57 2015 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Fri Aug 7 10:00:57 2015 -0700

----------------------------------------------------------------------
 hbase-shell/src/test/ruby/hbase/admin_test.rb | 203 +++++++++++++++++++++
 hbase-shell/src/test/ruby/test_helper.rb      |   8 +
 2 files changed, 211 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/832a6151/hbase-shell/src/test/ruby/hbase/admin_test.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb
index b643890..0a1a92e 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

http://git-wip-us.apache.org/repos/asf/hbase/blob/832a6151/hbase-shell/src/test/ruby/test_helper.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb
index 80eb4f5..67bbb14 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
 


Mime
View raw message