Skip to content

Commit af314fd

Browse files
committed
refactor Master UI tests
1 parent ca8a5fd commit af314fd

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

core/src/test/scala/org/apache/spark/deploy/master/MasterSuite.scala

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,7 @@ class MasterSuite extends SparkFunSuite
203203
html should include ("Spark Master at spark://")
204204
html should include ("""href="/static""")
205205
html should include ("""src="/static""")
206-
207-
val workerLinks = (WORKER_LINK_RE findAllMatchIn html).toList
208-
workerLinks.size should be (2)
209-
workerLinks foreach { case WORKER_LINK_RE(workerUrl, workerId) =>
210-
workerUrl should be (s"/proxy/$workerId")
211-
val url = s"$masterUrl/proxy/${workerId}/"
212-
System.setProperty("spark.ui.proxyBase", workerUrl)
213-
val workerHtml = Source.fromURL(url).getLines().mkString("\n")
214-
workerHtml should include ("Spark Worker at")
215-
workerHtml should include ("Running Executors (0)")
216-
verifyStaticResourcesServedByProxy(workerHtml, workerUrl)
217-
}
206+
verifyWorkerUI(html, masterUrl)
218207
}
219208
} finally {
220209
localCluster.stop()
@@ -244,6 +233,7 @@ class MasterSuite extends SparkFunSuite
244233
val url = s"$masterUrl/proxy/${workerId}/json"
245234
val workerResponse = parse(Source.fromURL(url).getLines().mkString("\n"))
246235
(workerResponse \ "cores").extract[Int] should be (2)
236+
(workerResponse \ "masterwebuiurl").extract[String] should be (reverseProxyUrl + "/")
247237
}
248238

249239
// with LocalCluster, we have masters and workers in the same JVM, each overwriting
@@ -255,27 +245,33 @@ class MasterSuite extends SparkFunSuite
255245
val html = Source.fromURL(s"$masterUrl/").getLines().mkString("\n")
256246
html should include ("Spark Master at spark://")
257247
verifyStaticResourcesServedByProxy(html, reverseProxyUrl)
258-
259-
val workerLinks = (WORKER_LINK_RE findAllMatchIn html).toList
260-
workerLinks.size should be (2)
261-
workerLinks foreach { case WORKER_LINK_RE(workerUrl, workerId) =>
262-
workerUrl should be (s"$reverseProxyUrl/proxy/$workerId")
263-
// there is no real front-end proxy as defined in $reverseProxyUrl
264-
// explicitly construct reverse proxy url directly targeting the master
265-
val url = s"$masterUrl/proxy/${workerId}/"
266-
System.setProperty("spark.ui.proxyBase", workerUrl)
267-
val workerHtml = Source.fromURL(url).getLines().mkString("\n")
268-
workerHtml should include ("Spark Worker at")
269-
workerHtml should include ("Running Executors (0)")
270-
verifyStaticResourcesServedByProxy(workerHtml, workerUrl)
271-
}
248+
verifyWorkerUI(html, masterUrl, reverseProxyUrl)
272249
}
273250
} finally {
274251
localCluster.stop()
275252
System.getProperties().remove("spark.ui.proxyBase")
276253
}
277254
}
278255

256+
private def verifyWorkerUI(masterHtml: String, masterUrl: String,
257+
reverseProxyUrl: String = ""): Unit = {
258+
val workerLinks = (WORKER_LINK_RE findAllMatchIn masterHtml).toList
259+
workerLinks.size should be (2)
260+
workerLinks foreach {
261+
case WORKER_LINK_RE(workerUrl, workerId) =>
262+
workerUrl should be (s"$reverseProxyUrl/proxy/$workerId")
263+
// there is no real front-end proxy as defined in $reverseProxyUrl
264+
// construct url directly targeting the master
265+
val url = s"$masterUrl/proxy/$workerId/"
266+
System.setProperty("spark.ui.proxyBase", workerUrl)
267+
val workerHtml = Source.fromURL(url).getLines().mkString("\n")
268+
workerHtml should include ("Spark Worker at")
269+
workerHtml should include ("Running Executors (0)")
270+
verifyStaticResourcesServedByProxy(workerHtml, workerUrl)
271+
case _ => fail // make sure we don't accidentially skip the tests
272+
}
273+
}
274+
279275
private def verifyStaticResourcesServedByProxy(html: String, proxyUrl: String): Unit = {
280276
html should not include ("""href="/static""")
281277
html should include (s"""href="$proxyUrl/static""")

0 commit comments

Comments
 (0)