Skip to content

Commit

Permalink
Uses random port for HiveThriftServer2 to avoid collision with parall…
Browse files Browse the repository at this point in the history
…el builds
  • Loading branch information
liancheng committed Jul 26, 2014
1 parent 090beea commit ac4618b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 4 additions & 3 deletions docs/sql-programming-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,10 @@ To start the JDBC server, run the following in the Spark directory:

./sbin/start-thriftserver.sh

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

./bin/beeline

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import java.io.{BufferedReader, InputStreamReader, PrintWriter}

import org.scalatest.{BeforeAndAfterAll, FunSuite}

import org.apache.spark.sql.hive.test.TestHive

class CliSuite extends FunSuite with BeforeAndAfterAll with TestUtils {
val WAREHOUSE_PATH = TestUtils.getWarehousePath("cli")
val METASTORE_PATH = TestUtils.getMetastorePath("cli")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._

import java.io.{BufferedReader, InputStreamReader}
import java.net.ServerSocket
import java.sql.{Connection, DriverManager, Statement}

import org.scalatest.{BeforeAndAfterAll, FunSuite}
Expand All @@ -39,9 +40,15 @@ class HiveThriftServer2Suite extends FunSuite with BeforeAndAfterAll with TestUt

val DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver"
val TABLE = "test"
// use a different port, than the hive standard 10000,
// for tests to avoid issues with the port being taken on some machines
val PORT = "10000"
val HOST = "localhost"
val PORT = {
// Let the system to choose a random available port to avoid collision with other parallel
// builds.
val socket = new ServerSocket(0)
val port = socket.getLocalPort
socket.close()
port
}

// If verbose is true, the test program will print all outputs coming from the Hive Thrift server.
val VERBOSE = Option(System.getenv("SPARK_SQL_TEST_VERBOSE")).getOrElse("false").toBoolean
Expand All @@ -66,6 +73,9 @@ class HiveThriftServer2Suite extends FunSuite with BeforeAndAfterAll with TestUt
"--hiveconf",
s"hive.metastore.warehouse.dir=$WAREHOUSE_PATH")
val pb = new ProcessBuilder(defaultArgs ++ args)
val environment = pb.environment()
environment.put("HIVE_SERVER2_THRIFT_PORT", PORT.toString)
environment.put("HIVE_SERVER2_THRIFT_BIND_HOST", HOST)
process = pb.start()
inputReader = new BufferedReader(new InputStreamReader(process.getInputStream))
errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream))
Expand Down

0 comments on commit ac4618b

Please sign in to comment.