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

    https://github.com/apache/spark/pull/5792#discussion_r31555464
  
    --- Diff: 
core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala ---
    @@ -147,6 +148,86 @@ class HistoryServerSuite extends FunSuite with 
BeforeAndAfter with Matchers with
         }
       }
     
    +  test("download all logs for app with multiple attempts") {
    +    doDownloadTest("local-1430917381535", None)
    +  }
    +
    +  test("download one log for app with multiple attempts") {
    +    (1 to 2).foreach { attemptId => doDownloadTest("local-1430917381535", 
Some(attemptId)) }
    +  }
    +
    +  test("download legacy logs - all attempts") {
    +    doDownloadTest("local-1426533911241", None, legacy = true)
    +  }
    +
    +  test("download legacy logs - single  attempts") {
    +    (1 to 2). foreach {
    +      attemptId => doDownloadTest("local-1426533911241", Some(attemptId), 
legacy = true)
    +    }
    +  }
    +
    +  // Test that the files are downloaded correctly, and validate them.
    +  def doDownloadTest(appId: String, attemptId: Option[Int], legacy: 
Boolean = false): Unit = {
    +
    +    def validateFile(expStream: FileInputStream, actualStream: 
FileInputStream): Unit = {
    +      try {
    +        val expected = IOUtils.toString(expStream)
    +        val actual = IOUtils.toString(actualStream)
    +        actual should be(expected)
    +      } finally {
    +        Seq(expStream, actualStream).foreach { s =>
    +          Utils.tryWithSafeFinally(s.close())()
    +        }
    +      }
    +    }
    +
    +    val url = attemptId match {
    +      case Some(id) =>
    +        new URL(s"${generateURL(s"applications/$appId")}/$id/logs")
    +      case None =>
    +        new URL(s"${generateURL(s"applications/$appId")}/logs")
    +    }
    +
    +    val (code, inputStream, error) = 
HistoryServerSuite.connectAndGetInputStream(url)
    +    code should be (HttpServletResponse.SC_OK)
    +    inputStream should not be None
    +    error should be (None)
    +
    +    val dir = Utils.createTempDir()
    +    try {
    +      Utils.chmod700(dir)
    +      HistoryTestUtils.unzipToDir(inputStream.get, dir)
    +      val unzippedContent = dir.listFiles()
    +      attemptId match {
    +        case Some(_) => unzippedContent.length should be (1)
    +        case None => unzippedContent.length should be (2)
    +      }
    +
    +      // If these are legacy files, then each of the unzipped contents is 
actually a legacy log dir.
    +      if (legacy) {
    +        unzippedContent.foreach { legacyDir =>
    +          assert(legacyDir.isDirectory)
    +          val logFiles = legacyDir.listFiles()
    +          logFiles.length should be (3)
    +          logFiles.foreach { f =>
    +            val actualStream = new FileInputStream(f)
    +            val expectedStream =
    +              new FileInputStream(new File(new File(logDir, 
legacyDir.getName), f.getName))
    +            validateFile(expectedStream, actualStream)
    +          }
    +        }
    +      } else {
    +        unzippedContent.foreach { f =>
    +          val actualStream = new FileInputStream(f)
    +          val expectedStream = new FileInputStream(new File(logDir, 
f.getName))
    +          validateFile(expectedStream, actualStream)
    +        }
    +      }
    +    } finally {
    +      Utils.deleteRecursively(dir)
    --- End diff --
    
    nit: not needed (see previous comment).


---
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