vy commented on a change in pull request #491:
URL: https://github.com/apache/logging-log4j2/pull/491#discussion_r627976020
##########
File path:
log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutNullEventDelimiterTest.java
##########
@@ -23,38 +23,38 @@
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
+import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.nio.file.Files;
+import java.nio.charset.StandardCharsets;
import java.net.BindException;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.Duration;
public class JsonTemplateLayoutNullEventDelimiterTest {
-
- // Set the configuration.
- static {
- System.setProperty(
- "log4j.configurationFile",
- "nullEventDelimitedJsonTemplateLayoutLogging.xml");
- }
-
- // Note that this port is hardcoded in the configuration file too!
- private static final int PORT = 50514;
-
@Test
public void test() throws Exception {
-
+ File tempConfig =
File.createTempFile("nullEventDelimitedJsonTemplateLayoutLogging", ".xml");
Review comment:
```suggestion
final File tempConfig =
File.createTempFile("nullEventDelimitedJsonTemplateLayoutLogging", ".xml");
```
##########
File path:
log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutNullEventDelimiterTest.java
##########
@@ -71,13 +71,24 @@ public void test() throws Exception {
// Verify the received log events.
final byte[] actualBytes = server.getReceivedBytes();
Assertions.assertThat(actualBytes).startsWith(expectedBytes);
-
- } catch (BindException bindException) {
- System.err.println("Required port " + PORT + " not available,
skipping " + getClass().getSimpleName());
+ } finally {
+ tempConfig.delete();
}
}
+ public void makeTempConfig(final int serverPort, final File
tempConfigFile) throws IOException {
+ try (FileOutputStream fos = new FileOutputStream(tempConfigFile);
+ OutputStreamWriter osw = new OutputStreamWriter(fos,
StandardCharsets.UTF_8);
+ BufferedWriter bw = new BufferedWriter(osw);) {
+ for (String line : Files.readAllLines(
Review comment:
```suggestion
try (final FileOutputStream fos = new
FileOutputStream(tempConfigFile);
final OutputStreamWriter osw = new OutputStreamWriter(fos,
StandardCharsets.UTF_8);
final BufferedWriter bw = new BufferedWriter(osw);) {
for (final String line : Files.readAllLines(
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]