Skip to content

Commit

Permalink
Explicitly pass host in SocketAppenderReconnectTest
Browse files Browse the repository at this point in the history
  • Loading branch information
vy committed Oct 1, 2024
1 parent 0721bc7 commit 1e3223c
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ void repeating_reconnect_failures_should_be_propagated() throws Exception {

// 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
Expand All @@ -93,7 +94,7 @@ void repeating_reconnect_failures_should_be_propagated() throws Exception {
verifyLoggingFailure(loggerContext, errorHandler);

// Start the server again, and verify the logging success.
server.start("Main", port);
server.start("Main", serverPort);
verifyLoggingSuccess(loggerContext, server, errorHandler);
}
}
Expand All @@ -119,9 +120,9 @@ void reconnect_should_fallback_when_there_are_multiple_resolved_hosts() throws E

// 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
Expand Down Expand Up @@ -213,7 +214,9 @@ void key_store_changes_should_be_detected_at_reconfigure(

// 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<
Expand All @@ -239,7 +242,8 @@ void key_store_changes_should_be_detected_at_reconfigure(
};

// 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
Expand All @@ -251,7 +255,7 @@ void key_store_changes_should_be_detected_at_reconfigure(

// 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)));
Expand Down Expand Up @@ -283,7 +287,8 @@ void key_store_changes_should_be_detected_at_reconfigure(
//
// 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
Expand All @@ -293,6 +298,7 @@ void key_store_changes_should_be_detected_at_reconfigure(
}

private static Configuration createConfiguration(
final String host,
final int port,
@Nullable
final BiFunction<
Expand All @@ -310,7 +316,7 @@ private static Configuration createConfiguration(
// 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)
Expand Down

0 comments on commit 1e3223c

Please sign in to comment.