Skip to content

Commit ac4618b

Browse files
committed
Uses random port for HiveThriftServer2 to avoid collision with parallel builds
1 parent 090beea commit ac4618b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

docs/sql-programming-guide.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,10 @@ To start the JDBC server, run the following in the Spark directory:
586586

587587
./sbin/start-thriftserver.sh
588588

589-
The default port the server listens on is 10000. You may run
590-
`./sbin/start-thriftserver.sh --help` for a complete list of all available
591-
options. Now you can use beeline to test the Thrift JDBC server:
589+
The default port the server listens on is 10000. To listen on customized host and port, please set
590+
the `HIVE_SERVER2_THRIFT_PORT` and `HIVE_SERVER2_THRIFT_BIND_HOST` environment variables. You may
591+
run `./sbin/start-thriftserver.sh --help` for a complete list of all available options. Now you can
592+
use beeline to test the Thrift JDBC server:
592593

593594
./bin/beeline
594595

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import java.io.{BufferedReader, InputStreamReader, PrintWriter}
2222

2323
import org.scalatest.{BeforeAndAfterAll, FunSuite}
2424

25-
import org.apache.spark.sql.hive.test.TestHive
26-
2725
class CliSuite extends FunSuite with BeforeAndAfterAll with TestUtils {
2826
val WAREHOUSE_PATH = TestUtils.getWarehousePath("cli")
2927
val METASTORE_PATH = TestUtils.getMetastorePath("cli")

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
2222
import scala.concurrent._
2323

2424
import java.io.{BufferedReader, InputStreamReader}
25+
import java.net.ServerSocket
2526
import java.sql.{Connection, DriverManager, Statement}
2627

2728
import 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

Comments
 (0)