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 08:15:43 UTC
[logging-log4j2] branch release-2.x updated: LOG4J2-3089 Fix
sporadic JsonTemplateLayoutNullEventDelimiterTest failures on Windows.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 7262964 LOG4J2-3089 Fix sporadic JsonTemplateLayoutNullEventDelimiterTest failures on Windows.
7262964 is described below
commit 72629641696d4db7bde9f5afb046b0e4264fae4f
Author: Volkan Yazici <vo...@gmail.com>
AuthorDate: Thu May 27 10:09:13 2021 +0200
LOG4J2-3089 Fix sporadic JsonTemplateLayoutNullEventDelimiterTest failures on Windows.
---
.../JsonTemplateLayoutNullEventDelimiterTest.java | 40 ++++++++++++----------
...nullEventDelimitedJsonTemplateLayoutLogging.xml | 2 +-
src/changes/changes.xml | 3 ++
3 files changed, 25 insertions(+), 20 deletions(-)
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..f4cfe84 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
@@ -31,35 +31,33 @@ 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;
+class JsonTemplateLayoutNullEventDelimiterTest {
@Test
- public void test() throws Exception {
-
- // Set the expected bytes.
- final byte[] expectedBytes = {
- '"', 'f', 'o', 'o', '"', '\0',
- '"', 'b', 'a', 'r', '"', '\0'
- };
+ void test() throws Exception {
// Start the TCP server.
- try (final TcpServer server = new TcpServer(PORT)) {
+ try (final TcpServer server = new TcpServer(0)) {
+
+ // Set the configuration.
+ System.setProperty(
+ "serverPort",
+ String.valueOf(server.getPort()));
+ System.setProperty(
+ "log4j.configurationFile",
+ "nullEventDelimitedJsonTemplateLayoutLogging.xml");
// Produce log events.
final Logger logger = LogManager.getLogger(JsonTemplateLayoutNullEventDelimiterTest.class);
logger.log(Level.INFO, "foo");
logger.log(Level.INFO, "bar");
+ // Set the expected bytes.
+ final byte[] expectedBytes = {
+ '"', 'f', 'o', 'o', '"', '\0',
+ '"', 'b', 'a', 'r', '"', '\0'
+ };
+
// Wait for the log events.
Awaitility
.await()
@@ -120,6 +118,10 @@ public class JsonTemplateLayoutNullEventDelimiterTest {
}
}
+ public int getPort() {
+ return serverSocket.getLocalPort();
+ }
+
public synchronized byte[] getReceivedBytes() {
return outputStream.toByteArray();
}
diff --git a/log4j-layout-template-json/src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml b/log4j-layout-template-json/src/test/resources/nullEventDelimitedJsonTemplateLayoutLogging.xml
index 547aac8..9eff27a 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="${sys:serverPort}"
protocol="TCP"
ignoreExceptions="false"
reconnectionDelay="100"
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c310dc9..ff9fd39 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,9 @@
Allow a PatternSelector to be specified on GelfLayout.
</action>
<!-- FIXES -->
+ <action issue="LOG4J2-3089" dev="vy" type="fix" due-to="Tim Perry">
+ Fix sporadic JsonTemplateLayoutNullEventDelimiterTest failures on Windows.
+ </action>
<action issue="LOG4J2-3075" dev="vy" type="fix">
Fix formatting of nanoseconds in JsonTemplateLayout.
</action>