Skip to content

Commit d4c4845

Browse files
committed
Fixes CliSuite
1 parent 75e80e2 commit d4c4845

File tree

1 file changed

+11
-12
lines changed
  • sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver

1 file changed

+11
-12
lines changed

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/CliSuite.scala

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ import scala.concurrent.{Await, Promise}
2525
import scala.sys.process.{Process, ProcessLogger}
2626

2727
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
28-
import org.scalatest.{BeforeAndAfter, BeforeAndAfterAll, FunSuite}
28+
import org.scalatest.{BeforeAndAfter, FunSuite}
2929

3030
import org.apache.spark.Logging
3131
import org.apache.spark.util.Utils
3232

33+
/**
34+
* A test suite for the `spark-sql` CLI tool. Note that all test cases share the same temporary
35+
* Hive metastore and warehouse.
36+
*/
3337
class CliSuite extends FunSuite with BeforeAndAfter with Logging {
3438
val warehousePath = Utils.createTempDir()
3539
val metastorePath = Utils.createTempDir()
@@ -58,18 +62,17 @@ class CliSuite extends FunSuite with BeforeAndAfter with Logging {
5862
| --master local
5963
| --hiveconf ${ConfVars.METASTORECONNECTURLKEY}=$jdbcUrl
6064
| --hiveconf ${ConfVars.METASTOREWAREHOUSE}=$warehousePath
61-
| --driver-class-path ${sys.props("java.class.path")}
6265
""".stripMargin.split("\\s+").toSeq ++ extraArgs
6366
}
6467

6568
var next = 0
6669
val foundAllExpectedAnswers = Promise.apply[Unit]()
67-
val queryStream = new ByteArrayInputStream(queries.mkString("\n").getBytes)
70+
// Explicitly adds ENTER for each statement to make sure they are actually entered into the CLI.
71+
val queryStream = new ByteArrayInputStream(queries.map(_ + "\n").mkString.getBytes)
6872
val buffer = new ArrayBuffer[String]()
6973
val lock = new Object
7074

7175
def captureOutput(source: String)(line: String): Unit = lock.synchronized {
72-
println(line)
7376
buffer += s"$source> $line"
7477
// If we haven't found all expected answers and another expected answer comes up...
7578
if (next < expectedAnswers.size && line.startsWith(expectedAnswers(next))) {
@@ -125,7 +128,7 @@ class CliSuite extends FunSuite with BeforeAndAfter with Logging {
125128
"SELECT COUNT(*) FROM hive_test;"
126129
-> "5",
127130
"DROP TABLE hive_test;"
128-
-> "Time taken: "
131+
-> "OK"
129132
)
130133
}
131134

@@ -162,12 +165,8 @@ class CliSuite extends FunSuite with BeforeAndAfter with Logging {
162165
val dataFilePath =
163166
Thread.currentThread().getContextClassLoader.getResource("data/files/small_kv.txt")
164167

165-
runCliWithin(1.minute,
166-
Seq(
167-
"--jars",
168-
s"$jarFile"))(
169-
"""
170-
|CREATE TABLE t1(key string, val string)
168+
runCliWithin(1.minute, Seq("--jars", s"$jarFile"))(
169+
"""CREATE TABLE t1(key string, val string)
171170
|ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe';
172171
""".stripMargin
173172
-> "OK",
@@ -176,7 +175,7 @@ class CliSuite extends FunSuite with BeforeAndAfter with Logging {
176175
s"LOAD DATA LOCAL INPATH '$dataFilePath' OVERWRITE INTO TABLE sourceTable;"
177176
-> "OK",
178177
"INSERT INTO TABLE t1 SELECT key, val FROM sourceTable;"
179-
-> "OK",
178+
-> "Time taken:",
180179
"SELECT count(key) FROM t1;"
181180
-> "5",
182181
"DROP TABLE t1;"

0 commit comments

Comments
 (0)