[SPARK-34590][TESTS] Allow JDWP debug for tests
### What changes were proposed in this pull request? This PR proposes a new feature that allows developers to debug test code using JDWP with sbt an Maven. More specifically, this PR introduces the following profile options. * `jdwp-test-debug`: An profile which controls enable/disable JDWP debug * `test.jdwp.address`: An option which corresponds to `address` option in JDWP * `test.jdwp.suspend`: An option which corresponds to `suspend` option in JDWP * `test.jdwp.server`: An option which corresponds to `server` option in JDWP * `test.debug.suite`: An option which controls whether debug ScalaStyle suites (Maven only) For `sbt`, this feature can be used like `build/sbt -Pjdwp-test-debug -Dtest.jdwp.address=localhost:9876 -Dtest.jdwp.suspend=y -Dtest.jdwp.server=y` and can be used for both JUnit tests and ScalaTest tests. For `Maven`, this feature can be used like as follows: (For JUnit tests) `build/mvn -Pjdwp-test-debug -Dtest.jdwp.address=localhost:9876 -Dtest.jdwp.suspend=y -Dtest.jdwp.server=y` (For ScalaTest suites) `build/mvn -Pjdwp-test-debug -Dtest.debug.suite=true -Dtest.jdwp.address=localhost:9876 -Dtest.jdwp.suspend=y -Dtest.jdwp.server=y` (It might be useful to specify specific sub-modules like `-pl sql/core,sql/catalyst`). ### Why are the changes needed? It's useful to debug test code. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? I confirmed the following things. * `jdwp-tes-debug` can switch JDWP enabled/disabled * `test.jdwp.address` can change address and port. * `test.jdwp.suspend` can change the behavior that the target debugee suspends or not. * `test.jdwp.server` can change the behavior that the JDWP debugger run as a server or client. * ScalaTest suites can be debugged with Maven with setting `test.debug.suite` to `true`. Closes #31706 from sarutak/sbt-jdwp. Authored-by: Kousuke Saruta <sarutak@oss.nttdata.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
This commit is contained in:
parent
5aaab19685
commit
33d1c16f53
14
pom.xml
14
pom.xml
|
@ -210,6 +210,11 @@
|
||||||
<test.exclude.tags></test.exclude.tags>
|
<test.exclude.tags></test.exclude.tags>
|
||||||
<test.include.tags></test.include.tags>
|
<test.include.tags></test.include.tags>
|
||||||
|
|
||||||
|
<test.jdwp.address>localhost:0</test.jdwp.address>
|
||||||
|
<test.jdwp.suspend>y</test.jdwp.suspend>
|
||||||
|
<test.jdwp.server>y</test.jdwp.server>
|
||||||
|
<test.debug.suite>false</test.debug.suite>
|
||||||
|
|
||||||
<!-- Package to use when relocating shaded classes. -->
|
<!-- Package to use when relocating shaded classes. -->
|
||||||
<spark.shade.packageName>org.sparkproject</spark.shade.packageName>
|
<spark.shade.packageName>org.sparkproject</spark.shade.packageName>
|
||||||
|
|
||||||
|
@ -3443,5 +3448,14 @@
|
||||||
</os>
|
</os>
|
||||||
</activation>
|
</activation>
|
||||||
</profile>
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>jdwp-test-debug</id>
|
||||||
|
<properties>
|
||||||
|
<jdwp.arg.line>-agentlib:jdwp=transport=dt_socket,suspend=${test.jdwp.suspend},server=${test.jdwp.server},address=${test.jdwp.address}</jdwp.arg.line>
|
||||||
|
<debugArgLine>${jdwp.arg.line}</debugArgLine>
|
||||||
|
<maven.surefire.debug>${jdwp.arg.line}</maven.surefire.debug>
|
||||||
|
<debugForkedProcess>${test.debug.suite}</debugForkedProcess>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -97,6 +97,9 @@ object SparkBuild extends PomBuild {
|
||||||
case Some(v) =>
|
case Some(v) =>
|
||||||
v.split("(\\s+|,)").filterNot(_.isEmpty).map(_.trim.replaceAll("-P", "")).toSeq
|
v.split("(\\s+|,)").filterNot(_.isEmpty).map(_.trim.replaceAll("-P", "")).toSeq
|
||||||
}
|
}
|
||||||
|
if (profiles.contains("jdwp-test-debug")) {
|
||||||
|
sys.props.put("test.jdwp.enabled", "true")
|
||||||
|
}
|
||||||
profiles
|
profiles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1071,6 +1074,19 @@ object TestSettings {
|
||||||
javaOptions in Test ++= "-Xmx4g -Xss4m -XX:+UseParallelGC -XX:-UseDynamicNumberOfGCThreads"
|
javaOptions in Test ++= "-Xmx4g -Xss4m -XX:+UseParallelGC -XX:-UseDynamicNumberOfGCThreads"
|
||||||
.split(" ").toSeq,
|
.split(" ").toSeq,
|
||||||
javaOptions += "-Xmx3g",
|
javaOptions += "-Xmx3g",
|
||||||
|
javaOptions in Test ++= {
|
||||||
|
val jdwpEnabled = sys.props.getOrElse("test.jdwp.enabled", "false").toBoolean
|
||||||
|
|
||||||
|
if (jdwpEnabled) {
|
||||||
|
val jdwpAddr = sys.props.getOrElse("test.jdwp.address", "localhost:0")
|
||||||
|
val jdwpServer = sys.props.getOrElse("test.jdwp.server", "y")
|
||||||
|
val jdwpSuspend = sys.props.getOrElse("test.jdwp.suspend", "y")
|
||||||
|
("-agentlib:jdwp=transport=dt_socket," +
|
||||||
|
s"suspend=$jdwpSuspend,server=$jdwpServer,address=$jdwpAddr").split(" ").toSeq
|
||||||
|
} else {
|
||||||
|
Seq.empty
|
||||||
|
}
|
||||||
|
},
|
||||||
// Exclude tags defined in a system property
|
// Exclude tags defined in a system property
|
||||||
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest,
|
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest,
|
||||||
sys.props.get("test.exclude.tags").map { tags =>
|
sys.props.get("test.exclude.tags").map { tags =>
|
||||||
|
|
Loading…
Reference in a new issue