Explicitly pass host in `SocketAppenderReconnectTest`
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 817545a..61d6528 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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
};
// 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 @@
// 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 @@
//
// 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 @@
}
private static Configuration createConfiguration(
+ final String host,
final int port,
@Nullable
final BiFunction<
@@ -310,7 +316,7 @@
// 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)