PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/hbase-shell/src/test/ruby/shell/rsgroup_shell_test.rb

http://github.com/apache/hbase
Ruby | 223 lines | 163 code | 40 blank | 20 comment | 0 complexity | 0668ae453c553e81368f025d7bb4e05e MD5 | raw file
Possible License(s): Apache-2.0, MIT
  1. #
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. require 'hbase_constants'
  20. require 'hbase_shell'
  21. module Hbase
  22. class RSGroupShellTest < Test::Unit::TestCase
  23. include HBaseConstants
  24. def setup
  25. @hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
  26. @shell = Shell::Shell.new(@hbase)
  27. connection = $TEST_CLUSTER.getConnection
  28. @admin = connection.getAdmin
  29. end
  30. def add_rsgroup_and_move_one_server(group_name)
  31. assert_nil(@admin.getRSGroup(group_name))
  32. @shell.command(:add_rsgroup, group_name)
  33. assert_not_nil(@admin.getRSGroup(group_name))
  34. hostport = @admin.getRSGroup('default').getServers.iterator.next
  35. @shell.command(:move_servers_rsgroup, group_name, [hostport.toString])
  36. assert_equal(1, @admin.getRSGroup(group_name).getServers.count)
  37. end
  38. def remove_rsgroup(group_name)
  39. rsgroup = @admin.getRSGroup(group_name)
  40. @admin.moveServersToRSGroup(rsgroup.getServers, 'default')
  41. @admin.removeRSGroup(group_name)
  42. assert_nil(@admin.getRSGroup(group_name))
  43. end
  44. define_test 'Test Basic RSGroup Commands' do
  45. group_name = 'test_group'
  46. table_name = 'test_table'
  47. @shell.command('create', table_name, 'f')
  48. @shell.command('add_rsgroup', group_name)
  49. assert_not_nil(@admin.getRSGroup(group_name))
  50. @shell.command('remove_rsgroup', group_name)
  51. assert_nil(@admin.getRSGroup(group_name))
  52. @shell.command('add_rsgroup', group_name)
  53. group = @admin.getRSGroup(group_name)
  54. assert_not_nil(group)
  55. assert_equal(0, group.getServers.count)
  56. hostport = @admin.getRSGroup('default').getServers.iterator.next
  57. @shell.command('get_rsgroup', 'default')
  58. hostPortStr = hostport.toString
  59. @shell.command('get_server_rsgroup', hostPortStr)
  60. @shell.command('move_servers_rsgroup',
  61. group_name,
  62. [hostPortStr])
  63. assert_equal(1, @admin.getRSGroup(group_name).getServers.count)
  64. assert_equal(group_name, @admin.getRSGroup(hostport).getName)
  65. @shell.command('move_tables_rsgroup',
  66. group_name,
  67. [table_name])
  68. assert_equal(1, @admin.listTablesInRSGroup(group_name).count)
  69. group = @hbase.rsgroup_admin.get_rsgroup(group_name)
  70. assert_not_nil(group)
  71. assert_equal(1, group.getServers.count)
  72. assert_equal(hostPortStr, group.getServers.iterator.next.toString)
  73. assert_equal(table_name, @admin.listTablesInRSGroup(group_name).iterator.next.toString)
  74. assert_equal(2, @hbase.rsgroup_admin.list_rs_groups.count)
  75. # just run it to verify jruby->java api binding
  76. @hbase.rsgroup_admin.balance_rs_group(group_name)
  77. @hbase.rsgroup_admin.balance_rs_group(group_name, 'force')
  78. @hbase.rsgroup_admin.balance_rs_group(group_name, 'dry_run')
  79. @shell.command(:disable, table_name)
  80. @shell.command(:drop, table_name)
  81. remove_rsgroup(group_name)
  82. end
  83. define_test 'Test RSGroup Move Namespace RSGroup Commands' do
  84. group_name = 'test_group'
  85. namespace_name = 'test_namespace'
  86. ns_table_name = 'test_namespace:test_ns_table'
  87. add_rsgroup_and_move_one_server(group_name)
  88. @shell.command(:create_namespace, namespace_name)
  89. @shell.command(:create, ns_table_name, 'f')
  90. @shell.command('move_namespaces_rsgroup',
  91. group_name,
  92. [namespace_name])
  93. assert_equal(1, @admin.listTablesInRSGroup(group_name).count)
  94. group = @hbase.rsgroup_admin.get_rsgroup(group_name)
  95. assert_not_nil(group)
  96. assert_true(@admin.listTablesInRSGroup(group_name).contains(org.apache.hadoop.hbase.TableName.valueOf(ns_table_name)))
  97. ns_table_name2 = 'test_namespace:test_ns_table2'
  98. @shell.command(:create, ns_table_name2, 'f')
  99. assert_true(@admin.listTablesInRSGroup(group_name).contains(org.apache.hadoop.hbase.TableName.valueOf(ns_table_name2)))
  100. assert_equal(2, @admin.listTablesInRSGroup(group_name).count)
  101. @shell.command(:disable, ns_table_name)
  102. @shell.command(:drop, ns_table_name)
  103. @shell.command(:disable, ns_table_name2)
  104. @shell.command(:drop, ns_table_name2)
  105. @shell.command(:drop_namespace, namespace_name)
  106. remove_rsgroup(group_name)
  107. end
  108. define_test 'Test RSGroup Move Server Namespace RSGroup Commands' do
  109. ns_group_name = 'test_ns_group'
  110. namespace_name = 'test_namespace'
  111. ns_table_name = 'test_namespace:test_ns_table'
  112. @shell.command('create_namespace', namespace_name)
  113. @shell.command('create', ns_table_name, 'f')
  114. @shell.command('add_rsgroup', ns_group_name)
  115. assert_not_nil(@admin.getRSGroup(ns_group_name))
  116. group_servers = @admin.getRSGroup('default').getServers
  117. hostport_str = group_servers.iterator.next.toString
  118. @shell.command('move_servers_namespaces_rsgroup',
  119. ns_group_name,
  120. [hostport_str],
  121. [namespace_name])
  122. ns_group = @hbase.rsgroup_admin.get_rsgroup(ns_group_name)
  123. assert_not_nil(ns_group)
  124. assert_equal(hostport_str, ns_group.getServers.iterator.next.toString)
  125. assert_equal(ns_table_name, @admin.listTablesInRSGroup(ns_group_name).iterator.next.toString)
  126. @shell.command(:disable, ns_table_name)
  127. @shell.command(:drop, ns_table_name)
  128. @shell.command(:drop_namespace, namespace_name)
  129. remove_rsgroup(ns_group_name)
  130. end
  131. # we test exceptions that could be thrown by the ruby wrappers
  132. define_test 'Test bogus arguments' do
  133. assert_raise(ArgumentError) do
  134. @hbase.rsgroup_admin().get_rsgroup('foobar')
  135. end
  136. assert_raise(ArgumentError) do
  137. @hbase.rsgroup_admin().get_rsgroup_of_server('foobar:123')
  138. end
  139. assert_raise(ArgumentError) do
  140. @hbase.rsgroup_admin().get_rsgroup_of_table('foobar')
  141. end
  142. end
  143. define_test 'Test rsgroup rename' do
  144. old_rs_group_name = 'test_group'
  145. new_rs_group_name = 'renamed_test_group'
  146. table_name = 'test_table'
  147. add_rsgroup_and_move_one_server(old_rs_group_name)
  148. @shell.command(:create, table_name, 'f')
  149. @shell.command(:move_tables_rsgroup, old_rs_group_name, [table_name])
  150. @hbase.rsgroup_admin.rename_rsgroup(old_rs_group_name, new_rs_group_name)
  151. assert_not_nil(@admin.getRSGroup(new_rs_group_name))
  152. assert_nil(@admin.getRSGroup(old_rs_group_name))
  153. assert_equal(1, @admin.getRSGroup(new_rs_group_name).getServers.count)
  154. assert_equal(1, @admin.listTablesInRSGroup(new_rs_group_name).count)
  155. assert_true(@admin.listTablesInRSGroup(new_rs_group_name).contains(org.apache.hadoop.hbase.TableName.valueOf(table_name)))
  156. @shell.command(:disable, table_name)
  157. @shell.command(:drop, table_name)
  158. remove_rsgroup(new_rs_group_name)
  159. end
  160. define_test 'Test alter rsgroup configuration' do
  161. group_name = 'test_group'
  162. add_rsgroup_and_move_one_server(group_name)
  163. @shell.command(:alter_rsgroup_config, group_name, { 'METHOD' => 'set', 'a' => 'a' })
  164. assert_equal(1, @admin.getRSGroup(group_name).getConfiguration.size)
  165. @shell.command(:alter_rsgroup_config, group_name, { 'METHOD' => 'unset', 'NAME' => 'a' })
  166. assert_equal(0, @admin.getRSGroup(group_name).getConfiguration.size)
  167. remove_rsgroup(group_name)
  168. end
  169. define_test 'Test set/unset rsgroup of table' do
  170. group_name = 'test_group'
  171. table_name = 'test_table'
  172. add_rsgroup_and_move_one_server(group_name)
  173. @shell.command('create', table_name, 'f')
  174. @shell.command(:alter, table_name, CONFIGURATION => { 'hbase.rsgroup.name' => group_name })
  175. assert_equal(1, @admin.listTablesInRSGroup(group_name).count)
  176. @shell.command(:alter, table_name, METHOD => 'table_conf_unset', NAME => 'hbase.rsgroup.name')
  177. assert_equal(0, @admin.listTablesInRSGroup(group_name).count)
  178. @shell.command(:disable, table_name)
  179. @shell.command(:drop, table_name)
  180. remove_rsgroup(group_name)
  181. end
  182. end
  183. end