aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Wendell <pwendell@gmail.com>2013-06-24 17:08:58 -0700
committerPatrick Wendell <pwendell@gmail.com>2013-06-24 17:12:55 -0700
commitd66bd6f8851e87c8f35cca86ee45e26a8f547040 (patch)
tree9488a0d8446530c4b0b1de94720d28b3ab5099d3
parentf7389330c35a6372c4c7b455b96b8498b9a9da27 (diff)
downloadspark-d66bd6f8851e87c8f35cca86ee45e26a8f547040.tar.gz
spark-d66bd6f8851e87c8f35cca86ee45e26a8f547040.tar.bz2
spark-d66bd6f8851e87c8f35cca86ee45e26a8f547040.zip
Adding another unit test to Web UI suite
-rw-r--r--core/src/main/scala/spark/deploy/master/ui/MasterWebUI.scala4
-rw-r--r--core/src/main/scala/spark/ui/JettyUtils.scala2
-rw-r--r--core/src/test/scala/spark/ui/UISuite.scala18
3 files changed, 19 insertions, 5 deletions
diff --git a/core/src/main/scala/spark/deploy/master/ui/MasterWebUI.scala b/core/src/main/scala/spark/deploy/master/ui/MasterWebUI.scala
index 50e93cd00f..dfefd6571b 100644
--- a/core/src/main/scala/spark/deploy/master/ui/MasterWebUI.scala
+++ b/core/src/main/scala/spark/deploy/master/ui/MasterWebUI.scala
@@ -15,7 +15,7 @@ import spark.ui.JettyUtils._
* Web UI server for the standalone master.
*/
private[spark]
-class MasterWebUI(val master: ActorRef, requestedPort: Option[Int]) extends Logging {
+class MasterWebUI(val master: ActorRef, requestedPort: Option[Int] = None) extends Logging {
implicit val timeout = Duration.create(
System.getProperty("spark.akka.askTimeout", "10").toLong, "seconds")
val host = Utils.localHostName()
@@ -33,7 +33,7 @@ class MasterWebUI(val master: ActorRef, requestedPort: Option[Int]) extends Logg
val (srv, bPort) = JettyUtils.startJettyServer("0.0.0.0", port, handlers)
server = Some(srv)
boundPort = Some(bPort)
- logInfo("Started Master web UI at http://%s:%d".format(host, boundPort))
+ logInfo("Started Master web UI at http://%s:%d".format(host, boundPort.get))
} catch {
case e: Exception =>
logError("Failed to create Master JettyUtils", e)
diff --git a/core/src/main/scala/spark/ui/JettyUtils.scala b/core/src/main/scala/spark/ui/JettyUtils.scala
index 1f665cbb42..45c0805b22 100644
--- a/core/src/main/scala/spark/ui/JettyUtils.scala
+++ b/core/src/main/scala/spark/ui/JettyUtils.scala
@@ -62,7 +62,7 @@ private[spark] object JettyUtils extends Logging {
}
}
- /** Creates a handler for serving files from a static directory. */
+ /** Creates a handler for serving files from a static directory */
def createStaticHandler(resourceBase: String): ResourceHandler = {
val staticHandler = new ResourceHandler
Option(getClass.getClassLoader.getResource(resourceBase)) match {
diff --git a/core/src/test/scala/spark/ui/UISuite.scala b/core/src/test/scala/spark/ui/UISuite.scala
index 6766b158f6..7df7356a6e 100644
--- a/core/src/test/scala/spark/ui/UISuite.scala
+++ b/core/src/test/scala/spark/ui/UISuite.scala
@@ -2,14 +2,28 @@ package spark.ui
import org.scalatest.FunSuite
import org.eclipse.jetty.server.Server
+import util.{Try, Success, Failure}
+import java.net.ServerSocket
class UISuite extends FunSuite {
test("jetty port increases under contention") {
val startPort = 33333
val server = new Server(startPort)
server.start()
- val (jettyServer, boundPort) = JettyUtils.startJettyServer("localhost", startPort, Seq())
- assert(boundPort === startPort + 1)
+ val (jettyServer1, boundPort1) = JettyUtils.startJettyServer("localhost", startPort, Seq())
+ val (jettyServer2, boundPort2) = JettyUtils.startJettyServer("localhost", startPort, Seq())
+
+ assert(boundPort1 === startPort + 1)
+ assert(boundPort2 === startPort + 2)
}
+ test("jetty binds to port 0 correctly") {
+ val (jettyServer, boundPort) = JettyUtils.startJettyServer("localhost", 0, Seq())
+ assert(jettyServer.getState === "STARTED")
+ assert(boundPort != 0)
+ Try {new ServerSocket(boundPort)} match {
+ case Success(s) => fail("Port %s doesn't seem used by jetty server".format(boundPort))
+ case Failure(e) =>
+ }
+ }
}