@@ -22,6 +22,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
2222import scala .concurrent ._
2323
2424import java .io .{BufferedReader , InputStreamReader }
25+ import java .net .ServerSocket
2526import java .sql .{Connection , DriverManager , Statement }
2627
2728import org .scalatest .{BeforeAndAfterAll , FunSuite }
@@ -39,9 +40,15 @@ class HiveThriftServer2Suite extends FunSuite with BeforeAndAfterAll with TestUt
3940
4041 val DRIVER_NAME = " org.apache.hive.jdbc.HiveDriver"
4142 val TABLE = " test"
42- // use a different port, than the hive standard 10000,
43- // for tests to avoid issues with the port being taken on some machines
44- val PORT = " 10000"
43+ val HOST = " localhost"
44+ val PORT = {
45+ // Let the system to choose a random available port to avoid collision with other parallel
46+ // builds.
47+ val socket = new ServerSocket (0 )
48+ val port = socket.getLocalPort
49+ socket.close()
50+ port
51+ }
4552
4653 // If verbose is true, the test program will print all outputs coming from the Hive Thrift server.
4754 val VERBOSE = Option (System .getenv(" SPARK_SQL_TEST_VERBOSE" )).getOrElse(" false" ).toBoolean
@@ -66,6 +73,9 @@ class HiveThriftServer2Suite extends FunSuite with BeforeAndAfterAll with TestUt
6673 " --hiveconf" ,
6774 s " hive.metastore.warehouse.dir= $WAREHOUSE_PATH" )
6875 val pb = new ProcessBuilder (defaultArgs ++ args)
76+ val environment = pb.environment()
77+ environment.put(" HIVE_SERVER2_THRIFT_PORT" , PORT .toString)
78+ environment.put(" HIVE_SERVER2_THRIFT_BIND_HOST" , HOST )
6979 process = pb.start()
7080 inputReader = new BufferedReader (new InputStreamReader (process.getInputStream))
7181 errorReader = new BufferedReader (new InputStreamReader (process.getErrorStream))
0 commit comments