From d9b175cbb6c88df573b21484d68c971897a3ba62 Mon Sep 17 00:00:00 2001 From: XinSun Date: Wed, 18 Nov 2020 14:29:02 +0800 Subject: [PATCH] HBASE-25289 [testing] Clean up resources after tests in rsgroup_shell_test.rb (#2672) Signed-off-by: Guanghao Zhang --- .../src/test/ruby/shell/rsgroup_shell_test.rb | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb b/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb index b8c1db264c4..f7c53000c85 100644 --- a/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb +++ b/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb @@ -30,6 +30,23 @@ module Hbase org.apache.hadoop.hbase.rsgroup.RSGroupAdminClient.new(connection) end + def add_rsgroup_and_move_one_server(group_name) + assert_nil(@rsgroup_admin.getRSGroupInfo(group_name)) + @shell.command(:add_rsgroup, group_name) + assert_not_nil(@rsgroup_admin.getRSGroupInfo(group_name)) + + hostport = @rsgroup_admin.getRSGroupInfo('default').getServers.iterator.next + @shell.command(:move_servers_rsgroup, group_name, [hostport.toString]) + assert_equal(1, @rsgroup_admin.getRSGroupInfo(group_name).getServers.count) + end + + def remove_rsgroup(group_name) + rsgroup = @rsgroup_admin.getRSGroupInfo(group_name) + @rsgroup_admin.moveServers(rsgroup.getServers, 'default') + @rsgroup_admin.removeRSGroup(group_name) + assert_nil(@rsgroup_admin.getRSGroupInfo(group_name)) + end + define_test 'Test Basic RSGroup Commands' do group_name = 'test_group' table_name = 'test_table' @@ -73,6 +90,10 @@ module Hbase # just run it to verify jruby->java api binding @hbase.rsgroup_admin.balance_rs_group(group_name) + + @shell.command(:disable, table_name) + @shell.command(:drop, table_name) + remove_rsgroup(group_name) end define_test 'Test RSGroup Move Namespace RSGroup Commands' do @@ -80,17 +101,24 @@ module Hbase namespace_name = 'test_namespace' ns_table_name = 'test_namespace:test_ns_table' + add_rsgroup_and_move_one_server(group_name) + @shell.command('create_namespace', namespace_name) @shell.command('create', ns_table_name, 'f') @shell.command('move_namespaces_rsgroup', group_name, [namespace_name]) - assert_equal(2, @rsgroup_admin.getRSGroupInfo(group_name).getTables.count) + assert_equal(1, @rsgroup_admin.getRSGroupInfo(group_name).getTables.count) group = @hbase.rsgroup_admin.get_rsgroup(group_name) assert_not_nil(group) assert_equal(ns_table_name, group.getTables.iterator.next.toString) + + @shell.command(:disable, ns_table_name) + @shell.command(:drop, ns_table_name) + @shell.command(:drop_namespace, namespace_name) + remove_rsgroup(group_name) end define_test 'Test RSGroup Move Server Namespace RSGroup Commands' do @@ -98,13 +126,11 @@ module Hbase namespace_name = 'test_namespace' ns_table_name = 'test_namespace:test_ns_table' + @shell.command('create_namespace', namespace_name) + @shell.command('create', ns_table_name, 'f') @shell.command('add_rsgroup', ns_group_name) assert_not_nil(@rsgroup_admin.getRSGroupInfo(ns_group_name)) - @shell.command('move_tables_rsgroup', - 'default', - [ns_table_name]) - group_servers = @rsgroup_admin.getRSGroupInfo('default').getServers hostport_str = group_servers.iterator.next.toString @shell.command('move_servers_namespaces_rsgroup', @@ -115,6 +141,11 @@ module Hbase assert_not_nil(ns_group) assert_equal(hostport_str, ns_group.getServers.iterator.next.toString) assert_equal(ns_table_name, ns_group.getTables.iterator.next.toString) + + @shell.command(:disable, ns_table_name) + @shell.command(:drop, ns_table_name) + @shell.command(:drop_namespace, namespace_name) + remove_rsgroup(ns_group_name) end # we test exceptions that could be thrown by the ruby wrappers @@ -135,26 +166,32 @@ module Hbase new_rs_group_name = 'renamed_test_group' table_name = 'test_table' + add_rsgroup_and_move_one_server(old_rs_group_name) + @shell.command(:create, table_name, 'f') + @shell.command(:move_tables_rsgroup, old_rs_group_name, [table_name]) + @hbase.rsgroup_admin.rename_rsgroup(old_rs_group_name, new_rs_group_name) assert_not_nil(@rsgroup_admin.getRSGroupInfo(new_rs_group_name)) assert_nil(@rsgroup_admin.getRSGroupInfo(old_rs_group_name)) assert_equal(1, @rsgroup_admin.getRSGroupInfo(new_rs_group_name).getServers.count) assert_equal(1, @rsgroup_admin.getRSGroupInfo(new_rs_group_name).getTables.count) assert_equal(table_name, @rsgroup_admin.getRSGroupInfo(new_rs_group_name).getTables.iterator.next.toString) + + @shell.command(:disable, table_name) + @shell.command(:drop, table_name) + remove_rsgroup(new_rs_group_name) end define_test 'Test alter rsgroup configuration' do - group_name = 'grp1' - @shell.command('add_rsgroup', group_name) - assert_not_nil(@rsgroup_admin.getRSGroupInfo(group_name)) + group_name = 'test_group' + add_rsgroup_and_move_one_server(group_name) - @hbase.rsgroup_admin.alter_rsgroup_config(group_name, {'METHOD' => 'set', 'a' => 'a'}) + @shell.command(:alter_rsgroup_config, group_name, { 'METHOD' => 'set', 'a' => 'a' }) assert_equal(1, @rsgroup_admin.getRSGroupInfo(group_name).getConfiguration.size) - @hbase.rsgroup_admin.alter_rsgroup_config(group_name, {'METHOD' => 'unset', 'NAME' => 'a'}) + @shell.command(:alter_rsgroup_config, group_name, { 'METHOD' => 'unset', 'NAME' => 'a' }) assert_equal(0, @rsgroup_admin.getRSGroupInfo(group_name).getConfiguration.size) - @shell.command('remove_rsgroup', group_name) - assert_nil(@rsgroup_admin.getRSGroupInfo(group_name)) + remove_rsgroup(group_name) end end end