@@ -208,18 +208,18 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
208208 child1.setLastModified(System .currentTimeMillis() - (1000 * 30 ))
209209
210210 // although child1 is old, child2 is still new so return true
211- assert(Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
211+ assert(Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
212212
213213 child2.setLastModified(System .currentTimeMillis - (1000 * 30 ))
214- assert(Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
214+ assert(Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
215215
216216 parent.setLastModified(System .currentTimeMillis - (1000 * 30 ))
217217 // although parent and its immediate children are new, child3 is still old
218218 // we expect a full recursive search for new files.
219- assert(Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
219+ assert(Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
220220
221221 child3.setLastModified(System .currentTimeMillis - (1000 * 30 ))
222- assert(! Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
222+ assert(! Utils .doesDirectoryContainAnyNewFiles(parent, 5 ))
223223 }
224224
225225 test(" resolveURI" ) {
@@ -339,21 +339,21 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
339339 assert(! tempDir1.exists())
340340
341341 val tempDir2 = Utils .createTempDir()
342- val tempFile1 = new File (tempDir2, " foo.txt" )
343- Files .touch(tempFile1 )
344- assert(tempFile1 .exists())
345- Utils .deleteRecursively(tempFile1 )
346- assert(! tempFile1 .exists())
342+ val sourceFile1 = new File (tempDir2, " foo.txt" )
343+ Files .touch(sourceFile1 )
344+ assert(sourceFile1 .exists())
345+ Utils .deleteRecursively(sourceFile1 )
346+ assert(! sourceFile1 .exists())
347347
348348 val tempDir3 = new File (tempDir2, " subdir" )
349349 assert(tempDir3.mkdir())
350- val tempFile2 = new File (tempDir3, " bar.txt" )
351- Files .touch(tempFile2 )
352- assert(tempFile2 .exists())
350+ val sourceFile2 = new File (tempDir3, " bar.txt" )
351+ Files .touch(sourceFile2 )
352+ assert(sourceFile2 .exists())
353353 Utils .deleteRecursively(tempDir2)
354354 assert(! tempDir2.exists())
355355 assert(! tempDir3.exists())
356- assert(! tempFile2 .exists())
356+ assert(! sourceFile2 .exists())
357357 }
358358
359359 test(" loading properties from file" ) {
@@ -386,30 +386,39 @@ class UtilsSuite extends FunSuite with ResetSystemProperties {
386386 }
387387
388388 test(" fetch hcfs dir" ) {
389- val tempDir = Utils .createTempDir()
390- val innerTempDir = Utils .createTempDir(tempDir.getPath)
391- val tempFile = File .createTempFile(" someprefix" , " somesuffix" , innerTempDir)
392- val targetDir = new File (" target-dir" )
393- Files .write(" some text" , tempFile, UTF_8 )
394-
395- try {
396- val path = new Path (" file://" + tempDir.getAbsolutePath)
397- val conf = new Configuration ()
398- val fs = Utils .getHadoopFileSystem(path.toString, conf)
399- Utils .fetchHcfsFile(path, targetDir, fs, new SparkConf (), conf, false )
400- assert(targetDir.exists())
401- assert(targetDir.isDirectory())
402- val newInnerDir = new File (targetDir, innerTempDir.getName)
403- println(" inner temp dir: " + innerTempDir.getName)
404- targetDir.listFiles().map(_.getName).foreach(println)
405- assert(newInnerDir.exists())
406- assert(newInnerDir.isDirectory())
407- val newInnerFile = new File (newInnerDir, tempFile.getName)
408- assert(newInnerFile.exists())
409- assert(newInnerFile.isFile())
410- } finally {
411- Utils .deleteRecursively(tempDir)
412- Utils .deleteRecursively(targetDir)
413- }
389+ val sourceDir = Utils .createTempDir()
390+ val innerSourceDir = Utils .createTempDir(root= sourceDir.getPath)
391+ val sourceFile = File .createTempFile(" someprefix" , " somesuffix" , innerSourceDir)
392+ val targetDir = new File (Utils .createTempDir(), " target-dir" )
393+ Files .write(" some text" , sourceFile, UTF_8 )
394+
395+ val path = new Path (" file://" + sourceDir.getAbsolutePath)
396+ val conf = new Configuration ()
397+ val fs = Utils .getHadoopFileSystem(path.toString, conf)
398+
399+ assert(! targetDir.isDirectory())
400+ Utils .fetchHcfsFile(path, targetDir, fs, new SparkConf (), conf, false )
401+ assert(targetDir.isDirectory())
402+
403+ // Copy again to make sure it doesn't error if the dir already exists.
404+ Utils .fetchHcfsFile(path, targetDir, fs, new SparkConf (), conf, false )
405+
406+ val destDir = new File (targetDir, sourceDir.getName())
407+ assert(destDir.isDirectory())
408+
409+ val destInnerDir = new File (destDir, innerSourceDir.getName)
410+ assert(destInnerDir.isDirectory())
411+
412+ val destInnerFile = new File (destInnerDir, sourceFile.getName)
413+ assert(destInnerFile.isFile())
414+
415+ val filePath = new Path (" file://" + sourceFile.getAbsolutePath)
416+ val testFileDir = new File (" test-filename" )
417+ val testFileName = " testFName"
418+ val testFilefs = Utils .getHadoopFileSystem(filePath.toString, conf)
419+ Utils .fetchHcfsFile(filePath, testFileDir, testFilefs, new SparkConf (),
420+ conf, false , Some (testFileName))
421+ val newFileName = new File (testFileDir, testFileName)
422+ assert(newFileName.isFile())
414423 }
415424}
0 commit comments