This is an automated email from the ASF dual-hosted git repository.
gengliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 941421144da6 [SPARK-48490][CORE][TESTS][FOLLOWUP] Add some UT for the
Windows paths scene
941421144da6 is described below
commit 941421144da67247e16b77ea86263dba341b1ad8
Author: panbingkun <[email protected]>
AuthorDate: Fri Jun 21 10:33:20 2024 -0700
[SPARK-48490][CORE][TESTS][FOLLOWUP] Add some UT for the Windows paths scene
### What changes were proposed in this pull request?
The pr is followup https://github.com/apache/spark/pull/47050
### Why are the changes needed?
Add some UT for the Windows paths scene.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass GA.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #47051 from panbingkun/SPARK-48490_FOLLOWUP_TESTS.
Authored-by: panbingkun <[email protected]>
Signed-off-by: Gengliang Wang <[email protected]>
---
.../apache/spark/util/PatternLoggingSuite.scala | 5 +++
.../apache/spark/util/StructuredLoggingSuite.scala | 38 ++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git
a/common/utils/src/test/scala/org/apache/spark/util/PatternLoggingSuite.scala
b/common/utils/src/test/scala/org/apache/spark/util/PatternLoggingSuite.scala
index 6af5f2d4f19f..2ba2b15c49f3 100644
---
a/common/utils/src/test/scala/org/apache/spark/util/PatternLoggingSuite.scala
+++
b/common/utils/src/test/scala/org/apache/spark/util/PatternLoggingSuite.scala
@@ -42,6 +42,11 @@ class PatternLoggingSuite extends LoggingSuiteBase with
BeforeAndAfterAll {
s""".*$level $className: This is a log message\nThis is a new line \t
other msg\n"""
}
+ override def expectedPatternForMsgWithMDCAndEscapeChar(level: Level): String
= {
+ s""".*$level $className: The first message\nthe first new line\tthe first
other msg\n""" +
+ s"""[\\s\\S]*The second message\nthe second new line\tthe second other
msg\n"""
+ }
+
override def expectedPatternForBasicMsgWithException(level: Level): String =
{
s""".*$level $className: This is a log message\n[\\s\\S]*"""
}
diff --git
a/common/utils/src/test/scala/org/apache/spark/util/StructuredLoggingSuite.scala
b/common/utils/src/test/scala/org/apache/spark/util/StructuredLoggingSuite.scala
index 10c240991bf3..52380b2edc7c 100644
---
a/common/utils/src/test/scala/org/apache/spark/util/StructuredLoggingSuite.scala
+++
b/common/utils/src/test/scala/org/apache/spark/util/StructuredLoggingSuite.scala
@@ -58,6 +58,11 @@ trait LoggingSuiteBase
def basicMsgWithEscapeCharMDC: LogEntry =
log"This is a log message\nThis is a new line \t other msg"
+ // scalastyle:off line.size.limit
+ def msgWithMDCAndEscapeChar: LogEntry =
+ log"The first message\nthe first new line\tthe first other
msg\n${MDC(LogKeys.PATHS,
"C:\\Users\\run-all_1.R\nC:\\Users\\run-all_2.R")}\nThe second message\nthe
second new line\tthe second other msg"
+ // scalastyle:on line.size.limit
+
def msgWithMDC: LogEntry = log"Lost executor ${MDC(LogKeys.EXECUTOR_ID,
"1")}."
def msgWithMDCValueIsNull: LogEntry = log"Lost executor
${MDC(LogKeys.EXECUTOR_ID, null)}."
@@ -77,6 +82,9 @@ trait LoggingSuiteBase
// test for basic message (with escape char mdc)
def expectedPatternForBasicMsgWithEscapeCharMDC(level: Level): String
+ // test for message (with mdc and escape char)
+ def expectedPatternForMsgWithMDCAndEscapeChar(level: Level): String
+
// test for basic message and exception
def expectedPatternForBasicMsgWithException(level: Level): String
@@ -130,6 +138,19 @@ trait LoggingSuiteBase
}
}
+ test("Logging with MDC and escape char") {
+ Seq(
+ (Level.ERROR, () => logError(msgWithMDCAndEscapeChar)),
+ (Level.WARN, () => logWarning(msgWithMDCAndEscapeChar)),
+ (Level.INFO, () => logInfo(msgWithMDCAndEscapeChar)),
+ (Level.DEBUG, () => logDebug(msgWithMDCAndEscapeChar)),
+ (Level.TRACE, () => logTrace(msgWithMDCAndEscapeChar))
+ ).foreach { case (level, logFunc) =>
+ val logOutput = captureLogOutput(logFunc)
+
assert(expectedPatternForMsgWithMDCAndEscapeChar(level).r.matches(logOutput))
+ }
+ }
+
test("Basic logging with Exception") {
val exception = new RuntimeException("OOM")
Seq(
@@ -218,6 +239,7 @@ class StructuredLoggingSuite extends LoggingSuiteBase {
jsonMapper.readTree(json).toString.
replace("<timestamp>", """[^"]+""").
replace(""""<stacktrace>"""", """.*""").
+ replace("<windows_paths>", """.*""").
replace("{", """\{""") + "\n"
}
@@ -254,6 +276,22 @@ class StructuredLoggingSuite extends LoggingSuiteBase {
}""")
}
+ override def expectedPatternForMsgWithMDCAndEscapeChar(level: Level): String
= {
+ // scalastyle:off line.size.limit
+ compactAndToRegexPattern(
+ s"""
+ {
+ "ts": "<timestamp>",
+ "level": "$level",
+ "msg": "The first message\\\\nthe first new line\\\\tthe first other
msg\\\\n<windows_paths>\\\\nThe second message\\\\nthe second new line\\\\tthe
second other msg",
+ "context": {
+ "paths": "<windows_paths>"
+ },
+ "logger": "$className"
+ }""")
+ // scalastyle:on line.size.limit
+ }
+
override def expectedPatternForBasicMsgWithException(level: Level): String =
{
compactAndToRegexPattern(
s"""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]