HBASE-26410 Fix HBase TestCanaryTool for Java17 (#3809)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
407a5bd812
commit
e1ca056676
|
@ -152,6 +152,21 @@ public class Addressing {
|
|||
return local;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an InetSocketAddress object returns a String represent of it.
|
||||
* This is a util method for Java 17. The toString() function of InetSocketAddress
|
||||
* will flag the unresolved address with a substring in the string, which will result
|
||||
* in unexpected problem. We should use this util function to get the string when we
|
||||
* not sure whether the input address is resolved or not.
|
||||
* @param address address to convert to a "host:port" String.
|
||||
* @return the String represent of the given address, like "foo:1234".
|
||||
*/
|
||||
public static String inetSocketAddress2String(InetSocketAddress address) {
|
||||
return address.isUnresolved() ?
|
||||
address.toString().replace("/<unresolved>", "") :
|
||||
address.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for AddressSelectionCondition to check if address is acceptable
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.tool;
|
|||
|
||||
import static org.apache.hadoop.hbase.HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT;
|
||||
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_ZNODE_PARENT;
|
||||
import static org.apache.hadoop.hbase.util.Addressing.inetSocketAddress2String;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.BindException;
|
||||
|
@ -1707,7 +1708,7 @@ public class CanaryTool implements Tool, Canary {
|
|||
new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));
|
||||
hosts = Lists.newArrayList();
|
||||
for (InetSocketAddress server : parser.getServerAddresses()) {
|
||||
hosts.add(server.toString());
|
||||
hosts.add(inetSocketAddress2String(server));
|
||||
}
|
||||
if (allowedFailures > (hosts.size() - 1) / 2) {
|
||||
LOG.warn(
|
||||
|
|
Loading…
Reference in New Issue