Skip to content
Snippets Groups Projects
Commit d66bd6f8 authored by Patrick Wendell's avatar Patrick Wendell
Browse files

Adding another unit test to Web UI suite

parent f7389330
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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 {
......
......@@ -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) =>
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment