HBASE-24890 The command regioninfo is not available (#2263)

* HBASE-24890 The command regioninfo is not available

* add ut for command regioninfo
This commit is contained in:
bsglz 2020-08-22 11:47:03 +08:00 committed by GitHub
parent 5b515de792
commit 4021f4577c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 5 deletions

View File

@ -16,6 +16,13 @@
# limitations under the License.
#
include Java
java_import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil
java_import org.apache.hadoop.hbase.util.FutureUtils
java_import org.apache.hadoop.hbase.client.ConnectionFactory
java_import org.apache.hadoop.hbase.security.UserProvider
java_import org.apache.hadoop.hbase.client.ClusterConnectionFactory
module Shell
module Commands
class Regioninfo < Command
@ -35,12 +42,20 @@ Below we pass first encoded region name and then full region name.
EOF
end
def command(regionname)
connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection()
admin = connection.getAdmin()
def command(region_name)
admin = @shell.hbase.connection.getAdmin()
sn = admin.getMaster()
puts org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.getRegionInfo(nil,
connection.getAdmin(sn), regionname.to_java_bytes)
conf = @shell.hbase.configuration
user = UserProvider.instantiate(conf).getCurrent()
clusterConnection = ClusterConnectionFactory.createAsyncClusterConnection(conf, nil, user)
regionInfo = ProtobufUtil.toRegionInfo(FutureUtils.get(
clusterConnection.getRegionServerAdmin(sn).getRegionInfo(
ProtobufUtil.getGetRegionInfoRequest(region_name.to_java_bytes))).getRegionInfo())
if clusterConnection != nil
clusterConnection.close()
end
puts regionInfo
end
end
end

View File

@ -435,5 +435,47 @@ class CommissioningTest < Test::Unit::TestCase
end
end
end
# Tests for the `regioninfo` shell command
class RegionInfoTest < Test::Unit::TestCase
include TestHelpers
include HBaseConstants
def setup
setup_hbase
# Create test table if it does not exist
@test_name = "hbase_shell_regioninfo_test"
drop_test_table(@test_name)
create_test_table(@test_name)
end
def teardown
shutdown
end
define_test "Get region info without any args" do
assert_raise(ArgumentError) do
command(:regioninfo)
end
end
define_test 'Get region info with encoded region name' do
region = command(:locate_region, @test_name, '')
encodedRegionName = region.getRegion.getEncodedName
output = capture_stdout { command(:regioninfo, encodedRegionName) }
puts "Region info output:\n#{output}"
assert output.include? 'ENCODED'
assert output.include? 'STARTKEY'
end
define_test 'Get region info with region name' do
region = command(:locate_region, @test_name, '')
regionName = region.getRegion.getRegionNameAsString
output = capture_stdout { command(:regioninfo, regionName) }
puts "Region info output:\n#{output}"
assert output.include? 'ENCODED'
assert output.include? 'STARTKEY'
end
end
# rubocop:enable ClassLength
end