@@ -26,22 +26,32 @@ import scala.concurrent.{Await, Promise}
2626import scala .sys .process .{Process , ProcessLogger }
2727
2828import org .apache .hadoop .hive .conf .HiveConf .ConfVars
29- import org .scalatest .{BeforeAndAfterAll , FunSuite }
29+ import org .scalatest .{BeforeAndAfter , BeforeAndAfterAll , FunSuite }
3030
3131import org .apache .spark .Logging
3232import org .apache .spark .util .Utils
3333
34- class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
34+ class CliSuite extends FunSuite with BeforeAndAfter with BeforeAndAfterAll with Logging {
35+ val warehousePath = Utils .createTempDir()
36+ val metastorePath = Utils .createTempDir()
37+
38+ before {
39+ warehousePath.delete()
40+ metastorePath.delete()
41+ }
42+
43+ after {
44+ warehousePath.delete()
45+ metastorePath.delete()
46+ }
47+
3548 def runCliWithin (
3649 timeout : FiniteDuration ,
37- extraArgs : Seq [String ] = Seq .empty)(
50+ extraArgs : Seq [String ] = Seq .empty
51+ )(
3852 queriesAndExpectedAnswers : (String , String )* ) {
3953
4054 val (queries, expectedAnswers) = queriesAndExpectedAnswers.unzip
41- val warehousePath = Utils .createTempDir()
42- warehousePath.delete()
43- val metastorePath = Utils .createTempDir()
44- metastorePath.delete()
4555 val cliScript = " ../../bin/spark-sql" .split(" /" ).mkString(File .separator)
4656
4757 val command = {
@@ -96,8 +106,6 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
96106 """ .stripMargin, cause)
97107 throw cause
98108 } finally {
99- warehousePath.delete()
100- metastorePath.delete()
101109 process.destroy()
102110 }
103111 }
@@ -125,4 +133,23 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
125133 test(" Single command with -e" ) {
126134 runCliWithin(1 .minute, Seq (" -e" , " SHOW DATABASES;" ))(" " -> " OK" )
127135 }
136+
137+ test(" Single command with --database" ) {
138+ runCliWithin(1 .minute)(
139+ " CREATE DATABASE hive_test_db;"
140+ -> " OK" ,
141+ " USE hive_test_db;"
142+ -> " OK" ,
143+ " CREATE TABLE hive_test(key INT, val STRING);"
144+ -> " OK" ,
145+ " SHOW TABLES;"
146+ -> " Time taken: "
147+ )
148+ runCliWithin(1 .minute, Seq (" --database" , " hive_test_db" , " -e" , " SHOW TABLES;" ))(
149+ " "
150+ -> " OK" ,
151+ " "
152+ -> " hive_test"
153+ )
154+ }
128155}
0 commit comments