attilapiros commented on code in PR #55720: URL: https://github.com/apache/spark/pull/55720#discussion_r3223901802
########## sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/application/ConnectReplE2ESuite.scala: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.application + +import java.util.concurrent.TimeUnit + +import scala.collection.mutable.ArrayBuffer +import scala.sys.process.BasicIO + +import org.apache.spark.sql.connect.test.{ConnectFunSuite, RemoteSparkSession} +import org.apache.spark.tags.AmmoniteTest + +@AmmoniteTest +class ConnectReplE2ESuite extends ConnectFunSuite with RemoteSparkSession { + + private def runSparkShell(): (Int, String, String) = { + val sparkHome = sys.props.getOrElse( + "spark.test.home", + sys.env.getOrElse("SPARK_HOME", fail("spark.test.home or SPARK_HOME not set"))) + val command = Seq(s"$sparkHome/bin/spark-shell", "--remote", s"sc://localhost:$serverPort") + + val process = new ProcessBuilder(command: _*).start() + // Close stdin immediately so shell exits on EOF + process.getOutputStream.close() + + val stdout = new ArrayBuffer[String]() + val stderr = new ArrayBuffer[String]() + val stdoutThread = new Thread() { + setDaemon(true) + override def run(): Unit = BasicIO.processFully(stdout += _)(process.getInputStream) + } + val stderrThread = new Thread() { + setDaemon(true) + override def run(): Unit = BasicIO.processFully(stderr += _)(process.getErrorStream) + } + stdoutThread.start() + stderrThread.start() + + val exited = process.waitFor(60, TimeUnit.SECONDS) + if (!exited) { + process.destroyForcibly() + fail("spark-shell did not exit within 60 seconds") + } + stdoutThread.join(10000) + stderrThread.join(10000) + (process.exitValue(), stdout.mkString("\n"), stderr.mkString("\n")) + } + + test("SPARK-56448: restarting spark-shell --remote does not throw NPE") { + // First invocation + val (exit1, _, stderr1) = runSparkShell() + assert(exit1 == 0, s"First spark-shell failed (exit=$exit1): $stderr1") + + // Second invocation -- without the fix, this would NPE from stale Ammonite cache + val (exit2, _, stderr2) = runSparkShell() + assert(exit2 == 0, s"Second spark-shell failed (exit=$exit2): $stderr2") + assert(!stderr2.contains("NullPointerException"), s"Second spark-shell threw NPE: $stderr2") Review Comment: This line cannot be reached and thus not needed. ########## sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/application/ConnectReplSuite.scala: ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.application + +import java.io.{ByteArrayInputStream, ByteArrayOutputStream} + +import ammonite.runtime.Storage +import ammonite.util.Bind + +import org.apache.spark.sql.connect.test.ConnectFunSuite + +class ConnectReplSuite extends ConnectFunSuite { Review Comment: I think this test is not needed anymore. ########## sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/application/ConnectReplE2ESuite.scala: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.application + +import java.util.concurrent.TimeUnit + +import scala.collection.mutable.ArrayBuffer +import scala.sys.process.BasicIO + +import org.apache.spark.sql.connect.test.{ConnectFunSuite, RemoteSparkSession} +import org.apache.spark.tags.AmmoniteTest + +@AmmoniteTest +class ConnectReplE2ESuite extends ConnectFunSuite with RemoteSparkSession { Review Comment: We already have a `ReplE2ESuite` but I agree better to have this in a separate suite. But as we have a connect REPL which `./bin/spark-connect-shell` what about renaming this test to `AmmoniteReplE2ESuite`? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
