nevzheng commented on code in PR #13517:
URL: https://github.com/apache/gravitino/pull/13517#discussion_r4147584946
##########
core/build.gradle.kts:
##########
@@ -103,7 +106,164 @@ artifacts {
add("testArtifacts", testJar)
}
+// Core's tests run in one of four Gradle lanes: coreUnitTest (default, no
Docker) and
+// coreH2Test/coreMySQLTest/corePostgreSQLTest (one per backend, coreMySQLTest
and
+// corePostgreSQLTest need Docker). Lane membership is decided purely by which
of the three
+// backend tags below a test class carries - see CoreBackend in
+// core/src/test/java/org/apache/gravitino/storage/relational/CoreBackend.java
for the typed
+// annotations (@CoreBackend.H2/.MySQL/.PostgreSQL/.All) that set them,
instead of writing raw
+// @Tag("...") strings by hand:
+// @CoreBackend.H2 -> runs only in coreH2Test
+// @CoreBackend.H2 @CoreBackend.MySQL -> runs in coreH2Test and
coreMySQLTest
+// @CoreBackend.All -> runs in all three backend lanes
+// (no CoreBackend annotation at all) -> a plain unit test, runs in
coreUnitTest
+// A class needing Docker but carrying no backend tag runs in no lane at all -
check locally
+// with `./gradlew :core:coreTestLaneOf
-PclassName=<fully.qualified.ClassName>`.
+//
+// Backend name -> JUnit tag that admits a test class to that backend's lane.
Adding a backend
+// here is enough to teach the lane filtering below about it; also add it to
CoreBackend.java.
+val coreBackendTestTags =
+ linkedMapOf(
+ "h2" to "gravitino-core-h2-test",
+ "mysql" to "gravitino-core-mysql-test",
+ "postgresql" to "gravitino-core-postgresql-test"
+ )
+val coreTestBackendProperty = "gravitino.core.test.backend"
+
+fun registerCoreTestTask(
+ taskName: String,
+ backend: String? = null
+) = tasks.register<Test>(taskName) {
+ group = "verification"
+ description =
+ if (backend == null) {
+ "Runs core unit tests."
+ } else {
+ "Runs core database tests against $backend."
+ }
+
+ testClassesDirs = sourceSets["test"].output.classesDirs
+ classpath = sourceSets["test"].runtimeClasspath
+
+ inputs.property("coreTestSuite", backend ?: "unit")
+ inputs.property("coreTestBackend", backend ?: "none")
+ // Distinct from the extensions.extraProperties["includeDockerTaggedTests"]
flag set below,
+ // which is a different mechanism (read by root build.gradle.kts's shared
test-environment
+ // setup to decide JUnit tag filtering) - this is only a Gradle
up-to-date-check input.
+ inputs.property("coreTestIncludesDockerTaggedTests", backend != null)
+
reports.junitXml.outputLocation.set(layout.buildDirectory.dir("test-results/$taskName"))
+ reports.html.outputLocation.set(
+ rootProject.layout.buildDirectory.dir("reports/tests/core/$taskName")
+ )
+
+ extensions.configure<JacocoTaskExtension> {
+ destinationFile =
layout.buildDirectory.file("jacoco/$taskName.exec").get().asFile
+ }
+
+ useJUnitPlatform {
+ if (backend == null) {
+ // Whatever carries no backend tag (and no Docker tag) is the unit suite.
+ excludeTags(*coreBackendTestTags.values.toTypedArray(),
"gravitino-docker-test")
+ } else {
+ val ownBackendTag =
+ coreBackendTestTags[backend]
+ ?: throw GradleException("Unsupported core test backend: $backend")
+ // Plain tag include, applied by JUnit at discovery time, so classes not
tagged for this
+ // backend never show up in this lane's JUnit XML. A class tagged for
several backends
+ // runs under each of them.
+ includeTags(ownBackendTag)
+ }
+ }
+
+ if (backend != null) {
+ systemProperty(coreTestBackendProperty, backend)
+ extensions.extraProperties["includeDockerTaggedTests"] = true
+
+ // Database tests mutate process-wide state and must remain sequential
within each lane.
+ maxParallelForks = 1
+ systemProperty("junit.jupiter.execution.parallel.enabled", "false")
+
+ if (backend != "h2") {
+ doFirst {
+ if (rootProject.extra["dockerTest"] != true) {
+ throw GradleException(
+ "$path requires Docker; use -PskipDockerTests=false with Docker
running."
+ )
+ }
+ }
+ }
+ }
+}
+
+registerCoreTestTask("coreUnitTest")
+registerCoreTestTask("coreH2Test", "h2")
+registerCoreTestTask("coreMySQLTest", "mysql")
+registerCoreTestTask("corePostgreSQLTest", "postgresql")
+
+tasks.register<JavaExec>("coreTestLaneOf") {
+ group = "verification"
+ description = "Prints which core database test lane(s) a class runs in, from
its tags, " +
+ "without running anything. Usage: -PclassName=<fully.qualified.ClassName>"
+ dependsOn(tasks.named("testClasses"))
+ classpath = sourceSets["test"].runtimeClasspath
+ mainClass.set("org.apache.gravitino.storage.relational.CoreTestLaneOf")
+ doFirst {
+ val className = project.findProperty("className") as? String
+ ?: throw GradleException(
+ "Usage: ./gradlew :core:coreTestLaneOf
-PclassName=<fully.qualified.ClassName>"
+ )
+ args(className)
+ }
+}
+
+val coreSuiteCoverage =
+
providers.gradleProperty("coreSuiteCoverage").map(String::toBoolean).orElse(false)
+val coreSuiteTaskNames =
+ listOf("coreUnitTest", "coreH2Test", "coreMySQLTest", "corePostgreSQLTest")
+val coreSuiteExecutionData =
+ coreSuiteTaskNames.map { layout.buildDirectory.file("jacoco/$it.exec") }
+val validateCoreSuiteCoverage by tasks.registering {
+ inputs.files(coreSuiteExecutionData)
+
+ doLast {
+ val missingExecutionData =
+ coreSuiteExecutionData
+ .map { it.get().asFile }
+ .filterNot { it.isFile && it.length() > 0L }
+ if (missingExecutionData.isNotEmpty()) {
+ throw GradleException(
+ "Missing core JaCoCo execution data:
${missingExecutionData.joinToString()}"
+ )
+ }
+ }
+}
+
+tasks.named<JacocoReport>("jacocoTestReport") {
+ if (coreSuiteCoverage.get()) {
+ dependsOn(tasks.named("classes"), validateCoreSuiteCoverage)
+ executionData.setFrom(coreSuiteExecutionData)
+ }
+}
+
+// :core:test is the java plugin's built-in `test` task, kept registered (and
working) only for
+// backward compatibility - IDEs and other tooling may still target it by
convention. It is
+// deprecated in place, not removed:
+// - Dev CUJ: a contributor running tests locally should target one of the
four lanes registered
+// above (coreUnitTest / coreH2Test / coreMySQLTest / corePostgreSQLTest),
never :core:test -
+// it predates the lane split and does not correspond to any CI lane. Check
where a class runs
+// with `./gradlew :core:coreTestLaneOf -PclassName=...` instead of
guessing.
+// - CI CUJ: no change needed here. CI never invokes :core:test -
dev/ci/test-shards.sh emits
+// `-x :core:test` for the `others` shard, so the warning below only ever
fires for a developer
+// running it directly.
Review Comment:
**polish:** Fixed in
https://github.com/apache/gravitino/pull/13517/commits/eb4e20a7982b395c2bb4903ee86b620923547e6b.
The comment now says only the `build` suite excludes `:core:test`; BackendIT
`others` still runs it under `-PskipTests`, where it matches nothing in core,
so the warning can show up in those logs too.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]