Skip to content

Commit b625bda

Browse files
ether1984wangjue
andauthored
HBASE-28754 verify the first argument passed to compaction_switch (#6119)
Co-authored-by: wangjue <ether1984@163.com> Signed-off-by: Duo Zhang <zhangduo@apache.org> Reviewed-by: guluo <lupeng_nwpu@qq.com> Reviewed-by: Chandra Sekhar K <chandrasekhar188k@gmail.com>
1 parent f4bcb76 commit b625bda

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

hbase-shell/src/main/ruby/hbase/admin.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def compact(table_or_region_name, family = nil, type = 'NORMAL')
114114
#----------------------------------------------------------------------------------------------
115115
# Switch compaction on/off at runtime on a region server
116116
def compaction_switch(on_or_off, regionserver_names)
117+
unless /true|false/i.match(on_or_off.to_s)
118+
raise ArgumentError, 'compaction_switch first argument only accepts "true" or "false"'
119+
end
117120
region_servers = regionserver_names.flatten.compact
118121
servers = java.util.ArrayList.new
119122
if region_servers.any?

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ def teardown
150150
command(:compaction_state, 'hbase:meta')
151151
end
152152

153+
#-------------------------------------------------------------------------------
154+
define_test "compaction_switch should work" do
155+
output = capture_stdout { command(:compaction_switch, false) }
156+
assert(output.include?('PREV_STATE'))
157+
output = capture_stdout { command(:compaction_switch, 'true') }
158+
assert(output.include?('PREV_STATE'))
159+
end
160+
153161
#-------------------------------------------------------------------------------
154162

155163
define_test "major_compact should work" do

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ def setup
6969
output = capture_stdout { @shell.command(name) }
7070
assert_match(/For usage try 'help "#{name}"'/, output)
7171
end
72+
73+
define_test 'Erroneous first argument for compaction_switch should indicate correct usage' do
74+
name = :compaction_switch
75+
output = capture_stdout { @shell.command(name, 'test') }
76+
assert_match(/compaction_switch first argument only accepts "true" or "false"/, output)
77+
end
7278
end
7379

7480
##

0 commit comments

Comments
 (0)