Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARK-2168 [Spark core] Use relative URIs for the app links in the History Server. #1160

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {

private def appRow(info: ApplicationHistoryInfo): Seq[Node] = {
val appName = if (info.started) info.name else info.logDirPath.getName
val uiAddress = parent.getAddress + info.ui.basePath
val uiAddress = info.ui.basePath
val startTime = if (info.started) UIUtils.formatDate(info.startTime) else "Not started"
val endTime = if (info.completed) UIUtils.formatDate(info.endTime) else "Not completed"
val difference = if (info.started && info.completed) info.endTime - info.startTime else -1L
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is weird here. Also, can you explain your comments "when" and "then"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the identation I was pretty sure it's fine when I was committing this one.

About "when" and "then", it's an old habit to simulate BDD-style of testing in Junit, however in Scala it could be replaced by using Specs2 or WordSpec trait from ScalaTest.

Let me know what u would like me to change.

}
}