This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 0b337245af5 HBASE-28754 verify the first argument passed to 
compaction_switch (#6119)
0b337245af5 is described below

commit 0b337245af5e27cdd85d3bed0d252fdccbbd4577
Author: ether1984 <[email protected]>
AuthorDate: Wed Mar 26 22:36:28 2025 +0800

    HBASE-28754 verify the first argument passed to compaction_switch (#6119)
    
    Co-authored-by: wangjue <[email protected]>
    Signed-off-by: Duo Zhang <[email protected]>
    Reviewed-by: guluo <[email protected]>
    Reviewed-by: Chandra Sekhar K <[email protected]>
    (cherry picked from commit b625bda1b2a7035e7626189392bcaaf02bd8832d)
---
 hbase-shell/src/main/ruby/hbase/admin.rb         | 3 +++
 hbase-shell/src/test/ruby/hbase/admin_test.rb    | 8 ++++++++
 hbase-shell/src/test/ruby/shell/commands_test.rb | 6 ++++++
 3 files changed, 17 insertions(+)

diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb 
b/hbase-shell/src/main/ruby/hbase/admin.rb
index 6264db63d5a..e0a48d0b9b4 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -101,6 +101,9 @@ module Hbase
     
#----------------------------------------------------------------------------------------------
     # Switch compaction on/off at runtime on a region server
     def compaction_switch(on_or_off, regionserver_names)
+      unless /true|false/i.match(on_or_off.to_s)
+        raise ArgumentError, 'compaction_switch first argument only accepts 
"true" or "false"'
+      end
       region_servers = regionserver_names.flatten.compact
       servers = java.util.ArrayList.new
       if region_servers.any?
diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb 
b/hbase-shell/src/test/ruby/hbase/admin_test.rb
index 9e19de3dbb0..dc8bb904ac4 100644
--- a/hbase-shell/src/test/ruby/hbase/admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb
@@ -140,6 +140,14 @@ module Hbase
       command(:compaction_state, 'hbase:meta')
     end
 
+    
#-------------------------------------------------------------------------------
+    define_test "compaction_switch should work" do
+      output = capture_stdout { command(:compaction_switch, false) }
+      assert(output.include?('PREV_STATE'))
+      output = capture_stdout { command(:compaction_switch, 'true') }
+      assert(output.include?('PREV_STATE'))
+    end
+
     
#-------------------------------------------------------------------------------
 
     define_test "major_compact should work" do
diff --git a/hbase-shell/src/test/ruby/shell/commands_test.rb 
b/hbase-shell/src/test/ruby/shell/commands_test.rb
index c97931ff20f..3acd885115e 100644
--- a/hbase-shell/src/test/ruby/shell/commands_test.rb
+++ b/hbase-shell/src/test/ruby/shell/commands_test.rb
@@ -69,6 +69,12 @@ class ShellCommandsErrorTest < Test::Unit::TestCase
     output = capture_stdout { @shell.command(name) }
     assert_match(/For usage try 'help "#{name}"'/, output)
   end
+
+  define_test 'Erroneous first argument for compaction_switch should indicate 
correct usage' do
+    name = :compaction_switch
+    output = capture_stdout { @shell.command(name, 'test') }
+    assert_match(/compaction_switch first argument only accepts "true" or 
"false"/, output)
+  end
 end
 
 ##

Reply via email to