Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6935#discussion_r46625956
  
    --- Diff: 
core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala ---
    @@ -281,6 +296,199 @@ class HistoryServerSuite extends SparkFunSuite with 
BeforeAndAfter with Matchers
         all (siteRelativeLinks) should startWith (uiRoot)
       }
     
    +  test("incomplete apps get refreshed") {
    +
    +    implicit val webDriver: WebDriver = new HtmlUnitDriver
    +    implicit val formats = org.json4s.DefaultFormats
    +
    +    // this test dir is explictly deleted on successful runs; retained for 
diagnostics when
    +    // not
    +    val logDir = 
Utils.createDirectory(System.getProperty("java.io.tmpdir", "logs"))
    +
    +    // a new conf is used with the background thread set and running at 
its fastest
    +    // alllowed refresh rate (1Hz)
    +    val myConf = new SparkConf()
    +      .set("spark.history.fs.logDirectory", logDir.getAbsolutePath)
    +      .set("spark.eventLog.dir", logDir.getAbsolutePath)
    +      .set("spark.history.fs.update.interval", "1s")
    +      .set("spark.eventLog.enabled", "true")
    +      .set("spark.history.cache.window", "250ms")
    +      .remove("spark.testing")
    +    val provider = new FsHistoryProvider(myConf)
    +    val securityManager = new SecurityManager(myConf)
    +
    +    val sc = new SparkContext("local", "test", myConf)
    +    val logDirUri = logDir.toURI
    +    val logDirPath = new Path(logDirUri)
    +    val fs = FileSystem.get(logDirUri, sc.hadoopConfiguration)
    +
    +    def listDir(dir: Path): Seq[FileStatus] = {
    +      val statuses = fs.listStatus(dir)
    +      statuses.flatMap(
    +        stat => if (stat.isDirectory) listDir(stat.getPath) else Seq(stat))
    +    }
    +
    +    def dumpLogDir(msg: String = ""): Unit = {
    +      if (log.isDebugEnabled) {
    +        logDebug(msg)
    +        listDir(logDirPath).foreach { status =>
    +          val s = status.toString
    +          logDebug(s)
    +        }
    +      }
    +    }
    +
    +    // stop the server with the old config, and start the new one
    +    server.stop()
    +    server = new HistoryServer(myConf, provider, securityManager, 18080)
    +    server.initialize()
    +    server.bind()
    +    try {
    +      val port = server.boundPort
    +      val metrics = server.cacheMetrics
    +
    +      def assertMetric(name: String, counter: Counter, expected: Long): 
Unit = {
    +        val actual = counter.getCount
    +        if (actual != expected) {
    +          // this is here because Scalatest loses stack depth
    +          throw new scala.Exception(s"Wrong $name value - expected 
$expected but got $actual" +
    +              s" in metrics\n$metrics")
    +        }
    +      }
    +
    +      def buildURL(appId: String, suffix: String): URL = {
    +        new URL(s"http://localhost:$port/history/$appId$suffix";)
    +      }
    +      val historyServerRoot = new URL(s"http://localhost:$port/";)
    +      val historyServerIncompleted = new URL(historyServerRoot, 
"?page=1&showIncomplete=true")
    +
    +      // assert the body of a URL contains a string; return that body
    +      def assertUrlContains(url: URL, str: String): String = {
    +        val body = HistoryServerSuite.getUrl(url)
    +        assert(body.contains(str), s"did not find $str at $url : $body")
    +        body
    +      }
    +
    +      // start initial job
    +      val d = sc.parallelize(1 to 10)
    +      d.count()
    +      val stdInterval = interval(100 milliseconds)
    +      val appId = eventually(timeout(20 seconds), stdInterval) {
    +        val json = getContentAndCode("applications", port)._2.get
    +        val apps = parse(json).asInstanceOf[JArray].arr
    +        apps should have size 1
    +        (apps.head \ "id").extract[String]
    +      }
    +
    +      // which lists as incomplete
    +      assertUrlContains(historyServerIncompleted, appId)
    +
    +      val appIdRoot = buildURL(appId, "")
    +      val rootAppPage = HistoryServerSuite.getUrl(appIdRoot)
    +      logDebug(s"$appIdRoot ->[${rootAppPage.length}] \n$rootAppPage")
    +      // sanity check to make sure filter is chaining calls
    +      rootAppPage should not be empty
    +
    +      def getAppUI: SparkUI = {
    +        provider.getAppUI(appId, None).get._1
    +      }
    +
    +      // selenium isn't that useful on failures...add our own reporting
    +      def getNumJobs(suffix: String): Int = {
    +        val target = buildURL(appId, suffix)
    +        val targetBody = HistoryServerSuite.getUrl(target)
    +        try {
    +          go to target.toExternalForm
    +          findAll(cssSelector("tbody tr")).toIndexedSeq.size
    +        }
    +        catch {
    +          case ex: Exception =>
    +            logError(s"Against $target\n$targetBody", ex)
    +            throw ex
    --- End diff --
    
    since this is just a test, wouldn't it be more useful to throw a new 
exception with the added msg, so its easier to see in tests?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to