|
17 | 17 |
|
18 | 18 | package org.apache.spark.sql.hive.thriftserver |
19 | 19 |
|
20 | | -import java.sql.{DriverManager, Statement} |
21 | 20 |
|
22 | | -import org.apache.hadoop.hive.conf.HiveConf.ConfVars |
23 | | -import org.apache.hive.jdbc.HiveDriver |
24 | | -import org.apache.spark.sql.hive.HiveContext |
25 | | -import org.apache.spark.sql.hive.thriftserver.HiveThriftServer2.HiveThriftServer2Listener |
26 | | -import org.apache.spark.sql.hive.thriftserver.ui.ThriftServerTab |
27 | | -import org.apache.spark.{SparkConf, SparkContext} |
| 21 | + |
| 22 | +import scala.util.Random |
| 23 | + |
28 | 24 | import org.openqa.selenium.WebDriver |
29 | 25 | import org.openqa.selenium.htmlunit.HtmlUnitDriver |
30 | | -import org.scalatest.{Matchers, BeforeAndAfterAll, FunSuite} |
| 26 | +import org.scalatest.{Matchers, BeforeAndAfterAll} |
31 | 27 | import org.scalatest.concurrent.Eventually._ |
32 | 28 | import org.scalatest.selenium.WebBrowser |
33 | 29 | import org.scalatest.time.SpanSugar._ |
34 | 30 |
|
| 31 | +import org.apache.hadoop.hive.conf.HiveConf.ConfVars |
| 32 | +import org.apache.spark.sql.hive.HiveContext |
35 | 33 |
|
36 | | -import scala.io.Source |
37 | | -import scala.util.Random |
38 | 34 |
|
39 | | -/** |
40 | | - * Created by tianyi on 4/27/15. |
41 | | - */ |
42 | | -class UISeleniumSuite extends FunSuite with WebBrowser with Matchers with BeforeAndAfterAll { |
| 35 | +class UISeleniumSuite extends HiveThriftJdbcTest with WebBrowser with Matchers with BeforeAndAfterAll { |
43 | 36 |
|
44 | 37 | implicit var webDriver: WebDriver = _ |
45 | 38 | var server: HiveThriftServer2 = _ |
46 | 39 | var hc: HiveContext = _ |
47 | 40 | val uiPort = 20000 + Random.nextInt(10000) |
48 | | - val listenPort = 10000 + Random.nextInt(10000) |
| 41 | + override def mode: ServerMode.Value = ServerMode.binary |
49 | 42 |
|
50 | 43 | override def beforeAll(): Unit = { |
51 | 44 | webDriver = new HtmlUnitDriver |
52 | | - startThriftServer |
| 45 | + super.beforeAll() |
53 | 46 | } |
54 | 47 |
|
55 | 48 | override def afterAll(): Unit = { |
56 | 49 | if (webDriver != null) { |
57 | 50 | webDriver.quit() |
58 | 51 | } |
59 | | - if (server != null) { |
60 | | - stopThriftServer |
61 | | - } |
| 52 | + super.afterAll() |
62 | 53 | } |
63 | 54 |
|
64 | | - def withMultipleConnectionJdbcStatement(fs: (Statement => Unit)*) { |
65 | | - val user = System.getProperty("user.name") |
66 | | - Class.forName(classOf[HiveDriver].getCanonicalName) |
67 | | - val connections = fs.map { |
68 | | - _ => DriverManager.getConnection(s"jdbc:hive2://localhost:$listenPort/", user, "") |
| 55 | + override protected def serverStartCommand(port: Int) = { |
| 56 | + val portConf = if (mode == ServerMode.binary) { |
| 57 | + ConfVars.HIVE_SERVER2_THRIFT_PORT |
| 58 | + } else { |
| 59 | + ConfVars.HIVE_SERVER2_THRIFT_HTTP_PORT |
69 | 60 | } |
70 | | - val statements = connections.map(_.createStatement()) |
71 | 61 |
|
72 | | - try { |
73 | | - statements.zip(fs).map { case (s, f) => f(s) } |
74 | | - } finally { |
75 | | - statements.map(_.close()) |
76 | | - connections.map(_.close()) |
77 | | - } |
78 | | - } |
79 | | - |
80 | | - def withJdbcStatement(f: Statement => Unit) { |
81 | | - withMultipleConnectionJdbcStatement(f) |
82 | | - } |
83 | | - |
84 | | - /** |
85 | | - * Create a test SparkContext with the SparkUI enabled. |
86 | | - * It is safe to `get` the SparkUI directly from the SparkContext returned here. |
87 | | - */ |
88 | | - private def startThriftServer: Unit = { |
89 | | - val conf = new SparkConf() |
90 | | - .setMaster("local") |
91 | | - .setAppName("test") |
92 | | - .set("spark.ui.enabled", "true") |
93 | | - .set("spark.ui.port", uiPort.toString) |
94 | | - hc = new HiveContext(new SparkContext(conf)) |
95 | | - hc.hiveconf.set(ConfVars.HIVE_SERVER2_THRIFT_PORT.toString, listenPort.toString) |
96 | | - server = new HiveThriftServer2(hc) |
97 | | - server.init(hc.hiveconf) |
98 | | - server.start() |
99 | | - HiveThriftServer2.listener = new HiveThriftServer2Listener(server, hc.conf) |
100 | | - hc.sparkContext.addSparkListener(HiveThriftServer2.listener) |
101 | | - HiveThriftServer2.uiTab = Some(new ThriftServerTab(hc.sparkContext)) |
102 | | - } |
103 | | - |
104 | | - private def stopThriftServer: Unit = { |
105 | | - server.stop() |
| 62 | + s"""$startScript |
| 63 | + | --master local |
| 64 | + | --hiveconf hive.root.logger=INFO,console |
| 65 | + | --hiveconf ${ConfVars.METASTORECONNECTURLKEY}=$metastoreJdbcUri |
| 66 | + | --hiveconf ${ConfVars.METASTOREWAREHOUSE}=$warehousePath |
| 67 | + | --hiveconf ${ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST}=localhost |
| 68 | + | --hiveconf ${ConfVars.HIVE_SERVER2_TRANSPORT_MODE}=$mode |
| 69 | + | --hiveconf $portConf=$port |
| 70 | + | --driver-class-path ${sys.props("java.class.path")} |
| 71 | + | --conf spark.ui.enabled=true |
| 72 | + | --conf spark.ui.port=$uiPort |
| 73 | + """.stripMargin.split("\\s+").toSeq |
106 | 74 | } |
107 | 75 |
|
108 | 76 | test("thrift server ui test") { |
109 | 77 | withJdbcStatement(statement =>{ |
| 78 | + val baseURL = s"http://localhost:${uiPort}" |
| 79 | + |
110 | 80 | val queries = Seq( |
111 | | - "DROP TABLE IF EXISTS test_map", |
112 | 81 | "CREATE TABLE test_map(key INT, value STRING)", |
113 | 82 | s"LOAD DATA LOCAL INPATH '${TestData.smallKv}' OVERWRITE INTO TABLE test_map") |
114 | 83 |
|
115 | 84 | queries.foreach(statement.execute) |
116 | 85 |
|
117 | 86 | eventually(timeout(10 seconds), interval(50 milliseconds)) { |
118 | | - go to (hc.sparkContext.ui.get.appUIAddress.stripSuffix("/")) |
| 87 | + go to (baseURL) |
119 | 88 | find(cssSelector("""ul li a[href*="ThriftServer"]""")) should not be(None) |
120 | 89 | } |
121 | 90 |
|
122 | 91 | eventually(timeout(10 seconds), interval(50 milliseconds)) { |
123 | | - go to (hc.sparkContext.ui.get.appUIAddress.stripSuffix("/") + "/ThriftServer") |
| 92 | + go to (baseURL + "/ThriftServer") |
124 | 93 | find(id("sessionstat")) should not be(None) |
125 | 94 | find(id("sqlstat")) should not be(None) |
126 | 95 |
|
|
0 commit comments