HyukjinKwon commented on code in PR #40675: URL: https://github.com/apache/spark/pull/40675#discussion_r1174696470
########## connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/application/ReplE2ESuite.scala: ########## @@ -0,0 +1,128 @@ +/* + * 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.{PipedInputStream, PipedOutputStream} +import java.util.concurrent.{Executors, Semaphore, TimeUnit} + +import org.apache.commons.io.output.ByteArrayOutputStream + +import org.apache.spark.sql.connect.client.util.RemoteSparkSession + +class ReplE2ESuite extends RemoteSparkSession { + + private val executorService = Executors.newSingleThreadExecutor() + private val TIMEOUT_SECONDS = 10 + + private var testSuiteOut: PipedOutputStream = _ + private var ammoniteOut: ByteArrayOutputStream = _ + private var errorStream: ByteArrayOutputStream = _ + private var ammoniteIn: PipedInputStream = _ + private val semaphore: Semaphore = new Semaphore(0) + + private def getCleanString(out: ByteArrayOutputStream): String = { + // Remove ANSI colour codes + // Regex taken from https://stackoverflow.com/a/25189932 + out.toString("UTF-8").replaceAll("\u001B\\[[\\d;]*[^\\d;]", "") + } + + override def beforeAll(): Unit = { + super.beforeAll() + ammoniteOut = new ByteArrayOutputStream() + testSuiteOut = new PipedOutputStream() + // Connect the `testSuiteOut` and `ammoniteIn` pipes + ammoniteIn = new PipedInputStream(testSuiteOut) + errorStream = new ByteArrayOutputStream() + + val args = Array("--port", serverPort.toString) + val task = new Runnable { + override def run(): Unit = { + ConnectRepl.doMain( + args = args, + semaphore = Some(semaphore), + inputStream = ammoniteIn, + outputStream = ammoniteOut, + errorStream = errorStream) + } + } + + executorService.submit(task) + } + + override def afterAll(): Unit = { + executorService.shutdownNow() + super.afterAll() + } + + def runCommandsInShell(input: String): String = { + require(input.nonEmpty) + // Pad the input with a semaphore release so that we know when the execution of the provided + // input is complete. + val paddedInput = input + '\n' + "semaphore.release()\n" + testSuiteOut.write(paddedInput.getBytes) + testSuiteOut.flush() + if (!semaphore.tryAcquire(TIMEOUT_SECONDS, TimeUnit.SECONDS)) { + val failOut = getCleanString(ammoniteOut) + val errOut = getCleanString(errorStream) + val errorString = + s""" + |REPL Timed out while running command: $input + |Console output: $failOut + |Error output: $errOut + |""".stripMargin + throw new RuntimeException(errorString) + } + getCleanString(ammoniteOut) + } + + def assertContains(message: String, output: String): Unit = { + val isContain = output.contains(message) + assert(isContain, "Ammonite output did not contain '" + message + "':\n" + output) + } + + test("Simple query") { Review Comment: This test consistently fails with JDK 17: ``` [info] ReplE2ESuite: [info] - Simple query *** FAILED *** (10 seconds, 4 milliseconds) [info] java.lang.RuntimeException: REPL Timed out while running command: [info] spark.sql("select 1").collect() [info] [info] Console output: [info] Error output: Compiling (synthetic)/ammonite/predef/ArgsPredef.sc [info] at org.apache.spark.sql.application.ReplE2ESuite.runCommandsInShell(ReplE2ESuite.scala:87) [info] at org.apache.spark.sql.application.ReplE2ESuite.$anonfun$new$1(ReplE2ESuite.scala:102) [info] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) [info] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85) [info] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83) [info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) [info] at org.scalatest.Transformer.apply(Transformer.scala:22) [info] at org.scalatest.Transformer.apply(Transformer.scala:20) [info] at org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(AnyFunSuiteLike.scala:226) [info] at org.scalatest.TestSuite.withFixture(TestSuite.scala:196) [info] at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195) [info] at org.scalatest.funsuite.AnyFunSuite.withFixture(AnyFunSuite.scala:1564) [info] at org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(AnyFunSuiteLike.scala:224) ``` https://github.com/apache/spark/actions/runs/4780630672/jobs/8498505928#step:9:4647 https://github.com/apache/spark/actions/runs/4774942961/jobs/8488946907 https://github.com/apache/spark/actions/runs/4769162286/jobs/8479293802 https://github.com/apache/spark/actions/runs/4759278349/jobs/8458399201 https://github.com/apache/spark/actions/runs/4748319019/jobs/8434392414 -- 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]
