alex-plekhanov commented on code in PR #12080: URL: https://github.com/apache/ignite/pull/12080#discussion_r2112132537
########## modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java: ########## @@ -334,13 +335,65 @@ public void testNotEmptyHostNameAttr() throws Exception { locHost = ip; checkHostNamesAttr(startGrid(nodeIdx++), false, false); - locHost = host; - checkHostNamesAttr(startGrid(nodeIdx++), false, false); + // If found host name, then check it. + if (host != null) { + locHost = host; + checkHostNamesAttr(startGrid(nodeIdx++), false, false); + } locHost = null; checkHostNamesAttr(startGrid(nodeIdx++), true, false); } + /** @return Host name, or {@code null} if all addresses are IPs. */ + private @Nullable String findHostName(Collection<String> addrs) { + return addrs.stream() + .filter(addr -> { + try { + // Skips optional IPv6 zone ID (e.g., fe80::1%lo0) because InetAddress#getByName might fail to parse it. + String[] parts = addr.split("%", 2); + + InetAddress inet = InetAddress.getByName(parts[0]); + + return !(inet instanceof Inet6Address) && !(inet instanceof Inet4Address); Review Comment: Strange logic. Addr - can be resolvable host (localhost for example), in this case we don't return this host. ########## modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java: ########## @@ -334,13 +335,65 @@ public void testNotEmptyHostNameAttr() throws Exception { locHost = ip; checkHostNamesAttr(startGrid(nodeIdx++), false, false); - locHost = host; - checkHostNamesAttr(startGrid(nodeIdx++), false, false); + // If found host name, then check it. + if (host != null) { + locHost = host; + checkHostNamesAttr(startGrid(nodeIdx++), false, false); + } locHost = null; checkHostNamesAttr(startGrid(nodeIdx++), true, false); } + /** @return Host name, or {@code null} if all addresses are IPs. */ + private @Nullable String findHostName(Collection<String> addrs) { + return addrs.stream() + .filter(addr -> { + try { + // Skips optional IPv6 zone ID (e.g., fe80::1%lo0) because InetAddress#getByName might fail to parse it. + String[] parts = addr.split("%", 2); + + InetAddress inet = InetAddress.getByName(parts[0]); + + return !(inet instanceof Inet6Address) && !(inet instanceof Inet4Address); + } + catch (Exception e) { + return true; // Failed to parse, then not an IP address. + } + }) + .findFirst() + .orElse(null); + } + + /** */ + @Test + public void testFindingAddresses() throws Exception { Review Comment: It's better to have private methods below tests -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org