You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2021/05/27 07:32:18 UTC
[logging-log4j2] branch master updated: LOG4J2-3088 LOG4J2-3089 Fix
windows build master (#491)
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new eb134e3 LOG4J2-3088 LOG4J2-3089 Fix windows build master (#491)
eb134e3 is described below
commit eb134e3b775d05869f98e48f72af44a99ed14792
Author: perry2of5 <pe...@yahoo.com>
AuthorDate: Thu May 27 00:31:24 2021 -0700
LOG4J2-3088 LOG4J2-3089 Fix windows build master (#491)
---
.../logging/log4j/core/config/FileOutputTest.java | 7 ++++
.../kafka/builder/ConfigurationBuilderTest.java | 27 ++++++++++---
.../JsonTemplateLayoutNullEventDelimiterTest.java | 46 +++++++++++++++-------
...nullEventDelimitedJsonTemplateLayoutLogging.xml | 2 +-
4 files changed, 62 insertions(+), 20 deletions(-)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
index 9479965..4818c4f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
@@ -16,17 +16,24 @@
*/
package org.apache.logging.log4j.core.config;
+
import org.apache.logging.log4j.test.junit.CleanUpFiles;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.junit.jupiter.api.Test;
+
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.condition.OS.WINDOWS;
+
+import org.junit.jupiter.api.condition.DisabledOnOs;
+@DisabledOnOs(WINDOWS) // FIXME: Fix status logger to close files so this will pass on windows.
@CleanUpFiles({"target/status.log", "target/test.log"})
public class FileOutputTest {
diff --git a/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/builder/ConfigurationBuilderTest.java b/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/builder/ConfigurationBuilderTest.java
index ac32df0..c35938b 100644
--- a/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/builder/ConfigurationBuilderTest.java
+++ b/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/builder/ConfigurationBuilderTest.java
@@ -16,10 +16,15 @@
*/
package org.apache.logging.log4j.kafka.builder;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
@@ -28,6 +33,7 @@ import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.junit.Test;
+import org.w3c.dom.Document;
public class ConfigurationBuilderTest {
@@ -106,14 +112,25 @@ public class ConfigurationBuilderTest {
INDENT + "</Loggers>" + EOL +
"</Configuration>" + EOL;
- // TODO make test run properly on Windows
@Test
public void testXmlConstructing() throws Exception {
- //assumeTrue(System.lineSeparator().length() == 1); // Only run test on platforms with single character line endings (such as Linux), not on Windows
final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
addTestFixtures("config name", builder);
final String xmlConfiguration = builder.toXmlConfiguration();
- assertEquals(expectedXml, xmlConfiguration);
- }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setCoalescing(true);
+ dbf.setIgnoringElementContentWhitespace(true);
+ dbf.setIgnoringComments(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ Document expected = db.parse(new ByteArrayInputStream(expectedXml.getBytes(StandardCharsets.UTF_8)));
+ expected.normalizeDocument();
+ Document actual = db.parse(new ByteArrayInputStream(xmlConfiguration.getBytes(StandardCharsets.UTF_8)));
+ actual.normalizeDocument();
+
+ assertTrue(actual.isEqualNode(expected), "Generated XML did not match expected XML.");
+ }
}
diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutNullEventDelimiterTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutNullEventDelimiterTest.java
index 80cce67..d2e02a5 100644
--- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutNullEventDelimiterTest.java
+++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutNullEventDelimiterTest.java
@@ -23,29 +23,25 @@ import org.assertj.core.api.Assertions;
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 {
-
+ final File tempConfig = File.createTempFile("nullEventDelimitedJsonTemplateLayoutLogging", ".xml");
// Set the expected bytes.
final byte[] expectedBytes = {
'"', 'f', 'o', 'o', '"', '\0',
@@ -53,7 +49,12 @@ public class JsonTemplateLayoutNullEventDelimiterTest {
};
// Start the TCP server.
- try (final TcpServer server = new TcpServer(PORT)) {
+ try (final TcpServer server = new TcpServer(0)) {
+ makeTempConfig(server.getLocalPort(), tempConfig);
+ System.setProperty(
+ "log4j.configurationFile",
+ tempConfig.getAbsolutePath());
+
// Produce log events.
final Logger logger = LogManager.getLogger(JsonTemplateLayoutNullEventDelimiterTest.class);
@@ -70,11 +71,24 @@ public class JsonTemplateLayoutNullEventDelimiterTest {
// Verify the received log events.
final byte[] actualBytes = server.getReceivedBytes();
Assertions.assertThat(actualBytes).startsWith(expectedBytes);
-
+ } finally {
+ tempConfig.delete();
}
}
+ public void makeTempConfig(final int serverPort, final File tempConfigFile) throws IOException {
+ try (final FileOutputStream fos = new FileOutputStream(tempConfigFile);
+ final OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
+ final BufferedWriter bw = new BufferedWriter(osw);) {
+ final File xmlTemplate = new File("src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml");
+ for (final String line : Files.readAllLines(xmlTemplate.toPath())) {
+ bw.write(line.replace("TARGET_PORT_NUMBER", Integer.toString(serverPort)));
+ bw.newLine();
+ }
+ }
+ }
+
private static final class TcpServer extends Thread implements AutoCloseable {
private final ServerSocket serverSocket;
@@ -94,6 +108,10 @@ public class JsonTemplateLayoutNullEventDelimiterTest {
start();
}
+ public int getLocalPort() {
+ return serverSocket.getLocalPort();
+ }
+
@Override
public void run() {
try {
diff --git a/log4j-layout-template-json/src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml b/log4j-layout-template-json/src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml
index 547aac8..f15bac2 100644
--- a/log4j-layout-template-json/src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml
+++ b/log4j-layout-template-json/src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml
@@ -19,7 +19,7 @@
<Appenders>
<Socket name="Socket"
host="localhost"
- port="50514"
+ port="TARGET_PORT_NUMBER"
protocol="TCP"
ignoreExceptions="false"
reconnectionDelay="100"