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:
parent
5b515de792
commit
4021f4577c
|
@ -16,6 +16,13 @@
|
||||||
# limitations under the License.
|
# 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 Shell
|
||||||
module Commands
|
module Commands
|
||||||
class Regioninfo < Command
|
class Regioninfo < Command
|
||||||
|
@ -35,12 +42,20 @@ Below we pass first encoded region name and then full region name.
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
def command(regionname)
|
def command(region_name)
|
||||||
connection = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection()
|
admin = @shell.hbase.connection.getAdmin()
|
||||||
admin = connection.getAdmin()
|
|
||||||
sn = admin.getMaster()
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -435,5 +435,47 @@ class CommissioningTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
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
|
# rubocop:enable ClassLength
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue