This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch 2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 1e3223cfa7e1a474ae1cc6872a475690bd402c4f Author: Volkan Yazıcı <[email protected]> AuthorDate: Tue Oct 1 10:36:28 2024 +0200 Explicitly pass host in `SocketAppenderReconnectTest` --- .../core/appender/SocketAppenderReconnectTest.java | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderReconnectTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderReconnectTest.java index 817545af16..61d6528708 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderReconnectTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderReconnectTest.java @@ -75,10 +75,11 @@ public class SocketAppenderReconnectTest { // Start the server. server.start("Main", EPHEMERAL_PORT); - final int port = server.getServerSocket().getLocalPort(); + final String serverHost = server.getServerSocket().getInetAddress().getHostAddress(); + final int serverPort = server.getServerSocket().getLocalPort(); // Initialize the logger context - final Configuration config = createConfiguration(port, null); + final Configuration config = createConfiguration(serverHost, serverPort, null); try (final LoggerContext loggerContext = createStartedLoggerContext(config)) { // Configure the error handler @@ -93,7 +94,7 @@ public class SocketAppenderReconnectTest { verifyLoggingFailure(loggerContext, errorHandler); // Start the server again, and verify the logging success. - server.start("Main", port); + server.start("Main", serverPort); verifyLoggingSuccess(loggerContext, server, errorHandler); } } @@ -119,9 +120,9 @@ public class SocketAppenderReconnectTest { // Initialize the logger context final Configuration config = createConfiguration( - // Passing an invalid port, since the resolution is supposed to be performed by the mocked host - // resolver anyway. - 0, null); + // Passing dummy host & port, since the resolution is supposed to be performed by the mocked + // host resolver anyway. + "localhost", 0, null); try (final LoggerContext loggerContext = createStartedLoggerContext(config)) { // Configure the error handler @@ -213,7 +214,9 @@ public class SocketAppenderReconnectTest { // Start the 1st server server1.start("1st", EPHEMERAL_PORT); - final int port = server1.getServerSocket().getLocalPort(); + final String server1Host = + server1.getServerSocket().getInetAddress().getHostAddress(); + final int server1Port = server1.getServerSocket().getLocalPort(); // Create the configuration transformer to add the `<Ssl>`, `<KeyStore>`, and `<TrustStore>` elements final BiFunction< @@ -239,7 +242,8 @@ public class SocketAppenderReconnectTest { }; // Initialize the logger context - final Configuration config1 = createConfiguration(port, appenderComponentBuilderTransformer); + final Configuration config1 = + createConfiguration(server1Host, server1Port, appenderComponentBuilderTransformer); try (final LoggerContext loggerContext = createStartedLoggerContext(config1)) { // Configure the error handler @@ -251,7 +255,7 @@ public class SocketAppenderReconnectTest { // Stop the 1st server and start the 2nd one (using different SSL configuration!) on the same port server1.close(); - server2.start("2nd", port); + server2.start("2nd", server1Port); // Stage the key store files using the 2nd `SSLContext` Files.write(keyStoreFilePath, Files.readAllBytes(Paths.get(keyStore2Location))); @@ -283,7 +287,8 @@ public class SocketAppenderReconnectTest { // // Hence, the only way is to programmatically build the very same configuration, twice, and use the 1st // one for initialization, and the 2nd one for reconfiguration. - final Configuration config2 = createConfiguration(port, appenderComponentBuilderTransformer); + final Configuration config2 = + createConfiguration(server1Host, server1Port, appenderComponentBuilderTransformer); loggerContext.reconfigure(config2); // Verify the working state on the 2nd server @@ -293,6 +298,7 @@ public class SocketAppenderReconnectTest { } private static Configuration createConfiguration( + final String host, final int port, @Nullable final BiFunction< @@ -310,7 +316,7 @@ public class SocketAppenderReconnectTest { // Create the appender configuration final AppenderComponentBuilder appenderComponentBuilder = configBuilder .newAppender(APPENDER_NAME, "Socket") - .addAttribute("host", "localhost") + .addAttribute("host", host) .addAttribute("port", port) .addAttribute("ignoreExceptions", false) .addAttribute("reconnectionDelayMillis", 10)
