Skip to content

Commit 38a1958

Browse files
committed
[SPARK-51603][CONNECT][TESTS] Auto ignore tests that require starting SparkConnectServer when the directory assembly/target/scala-2.13/jars/ not exist
### What changes were proposed in this pull request? After the merge of SPARK-48936 (#47402), the Maven module compilation order for the `connect-client-jvm` module was moved up to occur before the `assembly` build. Since a portion of the tests in `connect-client-jvm` heavily rely on `SparkConnectServer` and related dependencies being collected into `assembly/target/scala-2.13/jars/`, it is necessary to build `assembly` before running `mvn test` for `connect-client-jvm`. For example: ``` build/mvn clean install -DskipTests -Phive build/mvn test -pl sql/connect/client/jvm ``` This sequence will result in successful tests. However, if a full test suite is executed directly, such as: ``` build/mvn clean install -Phive ``` Failures similar to the following may occur: ``` [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.044 s <<< FAILURE! -- in org.apache.spark.sql.JavaEncoderSuite [ERROR] org.apache.spark.sql.JavaEncoderSuite -- Time elapsed: 0.044 s <<< FAILURE! java.lang.AssertionError: assertion failed: Fail to locate the target folder: '/Users/yangjie01/SourceCode/git/spark-maven/sql/connect/server/target'. SPARK_HOME='/Users/yangjie01/SourceCode/git/spark-maven'. Make sure the spark project jars has been built (e.g. using build/sbt package)and the env variable `SPARK_HOME` is set correctly. at scala.Predef$.assert(Predef.scala:279) at org.apache.spark.sql.connect.test.IntegrationTestUtils$.tryFindJar(IntegrationTestUtils.scala:138) at org.apache.spark.sql.connect.test.IntegrationTestUtils$.findJar(IntegrationTestUtils.scala:116) at org.apache.spark.sql.connect.test.SparkConnectServerUtils$.sparkConnect$lzycompute(RemoteSparkSession.scala:65) at org.apache.spark.sql.connect.test.SparkConnectServerUtils$.sparkConnect(RemoteSparkSession.scala:62) at org.apache.spark.sql.connect.test.SparkConnectServerUtils$.start(RemoteSparkSession.scala:135) at org.apache.spark.sql.connect.test.SparkConnectServerUtils$.createSparkSession(RemoteSparkSession.scala:181) at org.apache.spark.sql.connect.test.SparkConnectServerUtils.createSparkSession(RemoteSparkSession.scala) at org.apache.spark.sql.JavaEncoderSuite.setup(JavaEncoderSuite.java:42) at java.base/java.lang.reflect.Method.invoke(Method.java:569) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) Suppressed: java.lang.NullPointerException: Cannot invoke "org.apache.spark.sql.SparkSession.stop()" because "org.apache.spark.sql.JavaEncoderSuite.spark" is null at org.apache.spark.sql.JavaEncoderSuite.tearDown(JavaEncoderSuite.java:47) at java.base/java.lang.reflect.Method.invoke(Method.java:569) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1092) ... 1 more [INFO] [INFO] Results: [INFO] [ERROR] Failures: [ERROR] JavaEncoderSuite.setup:42 assertion failed: Fail to locate the target folder: '/Users/yangjie01/SourceCode/git/spark-maven/sql/connect/server/target'. SPARK_HOME='/Users/yangjie01/SourceCode/git/spark-maven'. Make sure the spark project jars has been built (e.g. using build/sbt package)and the env variable `SPARK_HOME` is set correctly. [INFO] [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 ``` To ensure that the above failing scenario can be tested successfully, the current pr makes the following changes: 1. Added `isAssemblyJarsDirExists` in `IntegrationTestUtils` to check if the directory `assembly/target/scala-2.13/jars/` exists. 2. Overrode the `test` function in the `trait RemoteSparkSession` from `AnyFunSuite` to ignore corresponding tests when `isAssemblyJarsDirExists` is `false`. Additionally, `RemoteSparkSession` will only try to start `SparkConnectServer` when `isAssemblyJarsDirExists` is `true`. 3. Made similar changes in `JavaEncoderSuite` as in step 2 ### Why are the changes needed? Make the Maven testing process smoother. ### Does this PR introduce _any_ user-facing change? No, just for maven test. ### How was this patch tested? - Pass Git Hub Actions - Tested the `connect-client-jvm` module using Maven without `assembly` dir , and the results met expectations. ### Was this patch authored or co-authored using generative AI tooling? No Closes #50396 from LuciferYang/SPARK-51603. Lead-authored-by: yangjie01 <yangjie01@baidu.com> Co-authored-by: YangJie <yangjie01@baidu.com> Signed-off-by: yangjie01 <yangjie01@baidu.com>
1 parent 0fdff1b commit 38a1958

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

sql/connect/client/jvm/src/test/java/org/apache/spark/sql/JavaEncoderSuite.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.apache.spark.sql.functions.*;
2929
import static org.apache.spark.sql.RowFactory.create;
3030
import org.apache.spark.api.java.function.MapFunction;
31+
import org.apache.spark.sql.connect.test.IntegrationTestUtils;
3132
import org.apache.spark.sql.connect.test.SparkConnectServerUtils;
3233
import org.apache.spark.sql.types.StructType;
3334

@@ -39,14 +40,18 @@ public class JavaEncoderSuite implements Serializable {
3940

4041
@BeforeAll
4142
public static void setup() {
43+
Assumptions.assumeTrue(IntegrationTestUtils.isAssemblyJarsDirExists(),
44+
"Skipping all tests because assembly jars directory does not exist.");
4245
spark = SparkConnectServerUtils.createSparkSession();
4346
}
4447

4548
@AfterAll
4649
public static void tearDown() {
47-
spark.stop();
48-
spark = null;
49-
SparkConnectServerUtils.stop();
50+
if (spark != null) {
51+
spark.stop();
52+
spark = null;
53+
SparkConnectServerUtils.stop();
54+
}
5055
}
5156

5257
private static BigDecimal bigDec(long unscaled, int scale) {

sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/test/IntegrationTestUtils.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ object IntegrationTestUtils {
9090
Files.exists(Paths.get(filePath))
9191
}
9292

93+
lazy val isAssemblyJarsDirExists: Boolean = {
94+
val filePath = s"$sparkHome/assembly/target/$scalaDir/jars/"
95+
Files.exists(Paths.get(filePath))
96+
}
97+
9398
private[sql] def cleanUpHiveClassesDirIfNeeded(): Unit = {
9499
def delete(f: File): Unit = {
95100
if (f.exists()) {

sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/test/RemoteSparkSession.scala

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import java.util.concurrent.TimeUnit
2323

2424
import scala.concurrent.duration.FiniteDuration
2525

26-
import org.scalatest.{BeforeAndAfterAll, Suite}
26+
import org.scalactic.source.Position
27+
import org.scalatest.{BeforeAndAfterAll, Suite, Tag}
2728
import org.scalatest.concurrent.Eventually.eventually
2829
import org.scalatest.concurrent.Futures.timeout
29-
import org.scalatest.time.SpanSugar._
30+
import org.scalatest.funsuite.AnyFunSuite // scalastyle:ignore funsuite
31+
import org.scalatest.time.SpanSugar._ // scalastyle:ignore
3032

3133
import org.apache.spark.SparkBuildInfo
3234
import org.apache.spark.sql.connect.SparkSession
@@ -205,14 +207,18 @@ object SparkConnectServerUtils {
205207
}
206208
}
207209

208-
trait RemoteSparkSession extends BeforeAndAfterAll { self: Suite =>
210+
trait RemoteSparkSession
211+
extends AnyFunSuite // scalastyle:ignore funsuite
212+
with BeforeAndAfterAll { self: Suite =>
209213
import SparkConnectServerUtils._
210214
var spark: SparkSession = _
211215
protected lazy val serverPort: Int = port
212216

213217
override def beforeAll(): Unit = {
214218
super.beforeAll()
215-
spark = createSparkSession()
219+
if (IntegrationTestUtils.isAssemblyJarsDirExists) {
220+
spark = createSparkSession()
221+
}
216222
}
217223

218224
override def afterAll(): Unit = {
@@ -224,4 +230,13 @@ trait RemoteSparkSession extends BeforeAndAfterAll { self: Suite =>
224230
spark = null
225231
super.afterAll()
226232
}
233+
234+
override protected def test(testName: String, testTags: Tag*)(testFun: => Any)(implicit
235+
pos: Position): Unit = {
236+
if (IntegrationTestUtils.isAssemblyJarsDirExists) {
237+
super.test(testName, testTags: _*)(testFun)
238+
} else {
239+
super.ignore(testName, testTags: _*)(testFun)
240+
}
241+
}
227242
}

0 commit comments

Comments
 (0)