@@ -18,16 +18,18 @@ package org.apache.spark.deploy.history
1818
1919import java .io .{File , FileInputStream , FileWriter , InputStream , IOException }
2020import java .net .{HttpURLConnection , URL }
21+ import java .util .zip .ZipInputStream
2122import javax .servlet .http .{HttpServletRequest , HttpServletResponse }
2223
24+ import com .google .common .base .Charsets
25+ import com .google .common .io .{ByteStreams , Files }
2326import org .apache .commons .io .{FileUtils , IOUtils }
2427import org .mockito .Mockito .when
2528import org .scalatest .{BeforeAndAfter , FunSuite , Matchers }
2629import org .scalatest .mock .MockitoSugar
2730
2831import org .apache .spark .{JsonTestUtils , SecurityManager , SparkConf }
2932import org .apache .spark .ui .SparkUI
30- import org .apache .spark .util .Utils
3133
3234/**
3335 * A collection of tests against the historyserver, including comparing responses from the json
@@ -169,18 +171,6 @@ class HistoryServerSuite extends FunSuite with BeforeAndAfter with Matchers with
169171 // Test that the files are downloaded correctly, and validate them.
170172 def doDownloadTest (appId : String , attemptId : Option [Int ], legacy : Boolean = false ): Unit = {
171173
172- def validateFile (expStream : FileInputStream , actualStream : FileInputStream ): Unit = {
173- try {
174- val expected = IOUtils .toString(expStream)
175- val actual = IOUtils .toString(actualStream)
176- actual should be(expected)
177- } finally {
178- Seq (expStream, actualStream).foreach { s =>
179- Utils .tryWithSafeFinally(s.close())()
180- }
181- }
182- }
183-
184174 val url = attemptId match {
185175 case Some (id) =>
186176 new URL (s " ${generateURL(s " applications/ $appId" )}/ $id/logs " )
@@ -193,39 +183,35 @@ class HistoryServerSuite extends FunSuite with BeforeAndAfter with Matchers with
193183 inputStream should not be None
194184 error should be (None )
195185
196- val dir = Utils .createTempDir()
197- try {
198- Utils .chmod700(dir)
199- HistoryTestUtils .unzipToDir(inputStream.get, dir)
200- val unzippedContent = dir.listFiles()
201- attemptId match {
202- case Some (_) => unzippedContent.length should be (1 )
203- case None => unzippedContent.length should be (2 )
204- }
205-
206- // If these are legacy files, then each of the unzipped contents is actually a legacy log dir.
186+ val zipStream = new ZipInputStream (inputStream.get)
187+ var entry = zipStream.getNextEntry
188+ entry should not be null
189+ val totalFiles = {
207190 if (legacy) {
208- unzippedContent.foreach { legacyDir =>
209- assert(legacyDir.isDirectory)
210- val logFiles = legacyDir.listFiles()
211- logFiles.length should be (3 )
212- logFiles.foreach { f =>
213- val actualStream = new FileInputStream (f)
214- val expectedStream =
215- new FileInputStream (new File (new File (logDir, legacyDir.getName), f.getName))
216- validateFile(expectedStream, actualStream)
217- }
218- }
191+ attemptId.map { x => 3 }.getOrElse(6 )
219192 } else {
220- unzippedContent.foreach { f =>
221- val actualStream = new FileInputStream (f)
222- val expectedStream = new FileInputStream (new File (logDir, f.getName))
223- validateFile(expectedStream, actualStream)
193+ attemptId.map { x => 1 }.getOrElse(2 )
194+ }
195+ }
196+ var filesCompared = 0
197+ while (entry != null ) {
198+ if (! entry.isDirectory) {
199+ val expectedFile = {
200+ if (legacy) {
201+ val splits = entry.getName.split(" /" )
202+ new File (new File (logDir, splits(0 )), splits(1 ))
203+ } else {
204+ new File (logDir, entry.getName)
205+ }
224206 }
207+ val expected = Files .toString(expectedFile, Charsets .UTF_8 )
208+ val actual = new String (ByteStreams .toByteArray(zipStream), Charsets .UTF_8 )
209+ actual should be (expected)
210+ filesCompared += 1
225211 }
226- } finally {
227- Utils .deleteRecursively(dir)
212+ entry = zipStream.getNextEntry
228213 }
214+ filesCompared should be (totalFiles)
229215 }
230216
231217 test(" response codes on bad paths" ) {
0 commit comments