From 6fc00a32503a74292e3c06341259aeff96d63904 Mon Sep 17 00:00:00 2001 From: Sakthi Date: Sat, 22 Dec 2018 20:13:23 -0800 Subject: [PATCH] HBASE-21634: Print error message when user uses unacceptable values for LIMIT while setting quotas. --- hbase-shell/src/main/ruby/hbase/quotas.rb | 4 ++-- .../src/test/ruby/hbase/quotas_test.rb | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/quotas.rb b/hbase-shell/src/main/ruby/hbase/quotas.rb index 38cb3e334dd0279e0522af4dfad188daac2a7feb..c9ad0b89223ea1d2900b17ea8c6f23e1ba7ce5b2 100644 --- a/hbase-shell/src/main/ruby/hbase/quotas.rb +++ b/hbase-shell/src/main/ruby/hbase/quotas.rb @@ -249,7 +249,7 @@ module Hbase def _parse_size(str_limit) str_limit = str_limit.downcase - match = /(\d+)([bkmgtp%]*)/.match(str_limit) + match = /^(\d+)([bkmgtp%]?)$/.match(str_limit) if match if match[2] == '%' return match[1].to_i @@ -263,7 +263,7 @@ module Hbase def _parse_limit(str_limit, type_cls, type) str_limit = str_limit.downcase - match = /(\d+)(req|cu|[bkmgtp])\/(sec|min|hour|day)/.match(str_limit) + match = /^(\d+)(req|cu|[bkmgtp])\/(sec|min|hour|day)$/.match(str_limit) if match if match[2] == 'req' limit = match[1].to_i diff --git a/hbase-shell/src/test/ruby/hbase/quotas_test.rb b/hbase-shell/src/test/ruby/hbase/quotas_test.rb index 981001a693db7420cf9f1014159ea36da47e7cd1..984af8f3951b64b8553466fecca1df697c2e551d 100644 --- a/hbase-shell/src/test/ruby/hbase/quotas_test.rb +++ b/hbase-shell/src/test/ruby/hbase/quotas_test.rb @@ -60,9 +60,27 @@ module Hbase end end - define_test 'set quota with a non-numeric limit fails' do + define_test 'set quota with an invalid limit fails' do assert_raise(ArgumentError) do command(:set_quota, TYPE => SPACE, LIMIT => 'asdf', POLICY => NO_INSERTS, TABLE => @test_name) + # Space Quota + command(:set_quota, TYPE => SPACE, LIMIT => '1.3G', \ + POLICY => NO_INSERTS, TABLE => @test_name) + command(:set_quota, TYPE => SPACE, LIMIT => 'G1G', \ + POLICY => NO_INSERTS, TABLE => @test_name) + command(:set_quota, TYPE => SPACE, LIMIT => '1GG', \ + POLICY => NO_INSERTS, TABLE => @test_name) + command(:set_quota, TYPE => SPACE, LIMIT => '1H', \ + POLICY => NO_INSERTS, TABLE => @test_name) + # Throttle Quota + command(:set_quota, TYPE => THROTTLE, LIMIT => '1.3G/hour', \ + TABLE => @test_name) + command(:set_quota, TYPE => THROTTLE, LIMIT => 'G1G/hour', \ + TABLE => @test_name) + command(:set_quota, TYPE => THROTTLE, LIMIT => '1GG/hour', \ + TABLE => @test_name) + command(:set_quota, TYPE => THROTTLE, LIMIT => '1H/hour', \ + TABLE => @test_name) end end -- 2.17.2 (Apple Git-113)