From ef021958be64d57991496b68d9b013ba9af01034 Mon Sep 17 00:00:00 2001 From: Sakthi Date: Wed, 9 Jan 2019 00:46:09 -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 | 53 ++++++++++++++++++- 2 files changed, 53 insertions(+), 4 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..c5be5a4680725ef968c4bd98812c48df4e16ba87 100644 --- a/hbase-shell/src/test/ruby/hbase/quotas_test.rb +++ b/hbase-shell/src/test/ruby/hbase/quotas_test.rb @@ -60,11 +60,60 @@ module Hbase end end - define_test 'set quota with a non-numeric limit fails' do + # rubocop:disable Metrics/BlockLength + 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 => 'asdf', + POLICY => NO_INSERTS, + TABLE => @test_name) + 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 => 'asdf', + TABLE => @test_name) + 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 + # rubocop:enable Metrics/BlockLength define_test 'set quota without a limit fails' do assert_raise(ArgumentError) do -- 2.17.2 (Apple Git-113)