hvanhovell commented on code in PR #40675: URL: https://github.com/apache/spark/pull/40675#discussion_r1158714617
########## connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/application/ReplE2ESuite.scala: ########## @@ -0,0 +1,123 @@ +/* + * 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) + + // Run simple query to test REPL + val output = runCommandsInShell("spark.sql(\"select 1\").collect()") Review Comment: use a multi-line string that is easier to read. `"""spark.sql("select 1").collect()"""` -- 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]
