From d6f4fbe58812492b0fd45939fa1bfcb7b8fb8080 Mon Sep 17 00:00:00 2001 From: Lukasz Jastrzebski Date: Wed, 25 Feb 2015 08:18:28 -0800 Subject: [PATCH 1/3] Added test for SPARK-2168 --- .../deploy/history/HistoryServerSuite.scala | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala diff --git a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala new file mode 100644 index 0000000000000..49c1aba2dc6d5 --- /dev/null +++ b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.deploy.history + +import org.scalatest.FunSuite +import org.scalatest.matchers.ShouldMatchers +import org.scalatest.mock.MockitoSugar +import javax.servlet.http.HttpServletRequest +import org.mockito.Mockito.{when} +import org.apache.hadoop.fs.Path +import org.apache.spark.ui.SparkUI +import scala.collection.mutable + +class HistoryServerSuite extends FunSuite with ShouldMatchers with MockitoSugar { + + val historyServer = mock[HistoryServer] + val request = mock[HttpServletRequest] + + test("generate history page with relative links") { + val ui = mock[SparkUI] + val link = "/history/app1.html" + val info = new ApplicationHistoryInfo("1", "app1", 0, 2, 1, "xxx", new Path("/tmp"), ui ) + val sampleHistory = mutable.HashMap("app1" -> info) + when(historyServer.appIdToInfo).thenReturn(sampleHistory) + when(ui.basePath).thenReturn(link) + when(historyServer.getAddress).thenReturn("http://localhost:123") + val page = new HistoryPage(historyServer) + + //when + val response = page.render(request) + + //then + val expectedLink = response \\ "a" + expectedLink.size should equal(1) + val hrefAttr = expectedLink(0).attribute("href") + hrefAttr.get.toString should equal(link) + } +} From 6d7866df70a1a612261bd30e003c0d1ab612537b Mon Sep 17 00:00:00 2001 From: Lukasz Jastrzebski Date: Wed, 25 Feb 2015 20:15:49 -0800 Subject: [PATCH 2/3] Adjusting test for SPARK-2168 for master branch --- .../deploy/history/HistoryServerSuite.scala | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala index 49c1aba2dc6d5..1ec3e0ffede85 100644 --- a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala +++ b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala @@ -17,7 +17,7 @@ package org.apache.spark.deploy.history import org.scalatest.FunSuite -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.Matchers import org.scalatest.mock.MockitoSugar import javax.servlet.http.HttpServletRequest import org.mockito.Mockito.{when} @@ -25,28 +25,29 @@ import org.apache.hadoop.fs.Path import org.apache.spark.ui.SparkUI import scala.collection.mutable -class HistoryServerSuite extends FunSuite with ShouldMatchers with MockitoSugar { +class HistoryServerSuite extends FunSuite with Matchers with MockitoSugar { val historyServer = mock[HistoryServer] val request = mock[HttpServletRequest] test("generate history page with relative links") { val ui = mock[SparkUI] - val link = "/history/app1.html" - val info = new ApplicationHistoryInfo("1", "app1", 0, 2, 1, "xxx", new Path("/tmp"), ui ) - val sampleHistory = mutable.HashMap("app1" -> info) - when(historyServer.appIdToInfo).thenReturn(sampleHistory) + val link = "/history/app1" + val info = new ApplicationHistoryInfo("app1", "app1", 0, 2, 1, "xxx", true ) + when(historyServer.getApplicationList()).thenReturn(Seq(info)) when(ui.basePath).thenReturn(link) - when(historyServer.getAddress).thenReturn("http://localhost:123") + when(historyServer.getProviderConfig()).thenReturn(Map[String, String]()) val page = new HistoryPage(historyServer) //when val response = page.render(request) //then - val expectedLink = response \\ "a" - expectedLink.size should equal(1) - val hrefAttr = expectedLink(0).attribute("href") - hrefAttr.get.toString should equal(link) + val links = response \\ "a" + val justHrefs = for { + l <- links + attrs <- l.attribute("href") + } yield (attrs.toString) + justHrefs should contain(link) } } From 0c07fab88a891049b973ef020683d09b69062fd3 Mon Sep 17 00:00:00 2001 From: Lukasz Jastrzebski Date: Thu, 26 Feb 2015 21:09:47 -0800 Subject: [PATCH 3/3] Incorporating comments for SPARK-2168 --- .../deploy/history/HistoryServerSuite.scala | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala index 1ec3e0ffede85..3a9963a5ce7b7 100644 --- a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala +++ b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala @@ -14,40 +14,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.spark.deploy.history +import javax.servlet.http.HttpServletRequest + +import scala.collection.mutable + +import org.apache.hadoop.fs.Path +import org.mockito.Mockito.{when} import org.scalatest.FunSuite import org.scalatest.Matchers import org.scalatest.mock.MockitoSugar -import javax.servlet.http.HttpServletRequest -import org.mockito.Mockito.{when} -import org.apache.hadoop.fs.Path + import org.apache.spark.ui.SparkUI -import scala.collection.mutable class HistoryServerSuite extends FunSuite with Matchers with MockitoSugar { - - val historyServer = mock[HistoryServer] - val request = mock[HttpServletRequest] - - test("generate history page with relative links") { + + test("generate history page with relative links") { + val historyServer = mock[HistoryServer] + val request = mock[HttpServletRequest] val ui = mock[SparkUI] val link = "/history/app1" - val info = new ApplicationHistoryInfo("app1", "app1", 0, 2, 1, "xxx", true ) + val info = new ApplicationHistoryInfo("app1", "app1", 0, 2, 1, "xxx", true) when(historyServer.getApplicationList()).thenReturn(Seq(info)) when(ui.basePath).thenReturn(link) when(historyServer.getProviderConfig()).thenReturn(Map[String, String]()) val page = new HistoryPage(historyServer) - + //when val response = page.render(request) - + //then - val links = response \\ "a" - val justHrefs = for { - l <- links - attrs <- l.attribute("href") - } yield (attrs.toString) - justHrefs should contain(link) + val links = response \\ "a" + val justHrefs = for { + l <- links + attrs <- l.attribute("href") + } yield (attrs.toString) + justHrefs should contain(link) } }