HBASE-13995 ServerName is not fully case insensitive

This commit is contained in:
Matteo Bertozzi 2015-07-01 09:20:25 -07:00
parent 348a11ad55
commit 5ee11840f6
2 changed files with 13 additions and 2 deletions

View File

@ -229,7 +229,7 @@ public class ServerName implements Comparable<ServerName>, Serializable {
*/
static String getServerName(String hostName, int port, long startcode) {
final StringBuilder name = new StringBuilder(hostName.length() + 1 + 5 + 1 + 13);
name.append(hostName);
name.append(hostName.toLowerCase());
name.append(SERVERNAME_SEPARATOR);
name.append(port);
name.append(SERVERNAME_SEPARATOR);
@ -314,7 +314,7 @@ public class ServerName implements Comparable<ServerName>, Serializable {
final ServerName right) {
if (left == null) return false;
if (right == null) return false;
return left.getHostname().equals(right.getHostname()) &&
return left.getHostname().compareToIgnoreCase(right.getHostname()) == 0 &&
left.getPort() == right.getPort();
}

View File

@ -108,5 +108,16 @@ public class TestServerName {
ServerName.getServerStartcodeFromServerName(sn.toString()));
}
@Test
public void testHostNameCaseSensitivity() {
ServerName lower = ServerName.valueOf("www.example.org", 1234, 5678);
ServerName upper = ServerName.valueOf("www.EXAMPLE.org", 1234, 5678);
assertEquals(0, lower.compareTo(upper));
assertEquals(0, upper.compareTo(lower));
assertEquals(lower.hashCode(), upper.hashCode());
assertTrue(lower.equals(upper));
assertTrue(upper.equals(lower));
assertTrue(ServerName.isSameHostnameAndPort(lower, upper));
}
}