-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#251 Fix glob support and divibility check for large amount of files.
- Loading branch information
Showing
4 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../test/scala/za/co/absa/cobrix/spark/cobol/source/regression/Test07IgnoreHiddenFiles.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package za.co.absa.cobrix.spark.cobol.source.regression | ||
|
||
import java.io.{DataOutputStream, File, FileOutputStream} | ||
import java.nio.file.{FileSystem, Files, Path, Paths} | ||
|
||
import org.apache.hadoop.fs.{FileSystem => HadoopFs} | ||
import org.scalatest.FunSuite | ||
import za.co.absa.cobrix.spark.cobol.source.base.SparkTestBase | ||
import za.co.absa.cobrix.spark.cobol.source.fixtures.BinaryFileFixture | ||
import za.co.absa.cobrix.spark.cobol.utils.FileUtils | ||
|
||
class Test07IgnoreHiddenFiles extends FunSuite with BinaryFileFixture with SparkTestBase { | ||
private val fileSystem = HadoopFs.get(spark.sparkContext.hadoopConfiguration) | ||
|
||
test("Test findAndLogFirstNonDivisibleFile() finds a file") { | ||
withTempDirectory("testHidden1") { tmpDir => | ||
createFileSize1(Files.createFile(Paths.get(tmpDir, "a"))) | ||
assert(FileUtils.findAndLogFirstNonDivisibleFile(tmpDir, 2, fileSystem)) | ||
assert(FileUtils.findAndLogAllNonDivisibleFiles(tmpDir, 2, fileSystem) == 1) | ||
} | ||
} | ||
|
||
test("Test findAndLogFirstNonDivisibleFile() ignores a hidden file") { | ||
withTempDirectory("testHidden1") { tmpDir => | ||
createFileSize1(Files.createFile(Paths.get(tmpDir, ".a"))) | ||
assert(!FileUtils.findAndLogFirstNonDivisibleFile(tmpDir, 2, fileSystem)) | ||
assert(FileUtils.findAndLogAllNonDivisibleFiles(tmpDir, 2, fileSystem) == 0) | ||
} | ||
} | ||
|
||
test("Test findAndLogFirstNonDivisibleFile() ignores a hidden file in a nested dir") { | ||
withTempDirectory("testHidden3") { tmpDir => | ||
Files.createDirectory(Paths.get(tmpDir, "dir1")) | ||
createFileSize1(Files.createFile(Paths.get(tmpDir, "dir1", ".b2"))) | ||
assert(!FileUtils.findAndLogFirstNonDivisibleFile(tmpDir, 2, fileSystem)) | ||
assert(FileUtils.findAndLogAllNonDivisibleFiles(tmpDir, 2, fileSystem) == 0) | ||
} | ||
} | ||
|
||
test("Test findAndLogFirstNonDivisibleFile() ignores a hidden dir") { | ||
withTempDirectory("testHidden4") { tmpDir => | ||
Files.createDirectory(Paths.get(tmpDir, ".dir2")) | ||
createFileSize1(Files.createFile(Paths.get(tmpDir, ".dir2", "c1"))) | ||
assert(!FileUtils.findAndLogFirstNonDivisibleFile(tmpDir, 2, fileSystem)) | ||
assert(FileUtils.findAndLogAllNonDivisibleFiles(tmpDir, 2, fileSystem) == 0) | ||
} | ||
} | ||
|
||
test("Test findAndLogFirstNonDivisibleFile() works with globbing") { | ||
withTempDirectory("testHidden1") { tmpDir => | ||
createFileSize1(Files.createFile(Paths.get(tmpDir, "a"))) | ||
assert(FileUtils.findAndLogFirstNonDivisibleFile(s"$tmpDir/*", 2, fileSystem)) | ||
assert(FileUtils.findAndLogAllNonDivisibleFiles(tmpDir, 2, fileSystem) == 1) | ||
} | ||
} | ||
|
||
|
||
private def createFileSize1(path: Path): Unit = { | ||
val file = new File(path.toAbsolutePath.toString) | ||
val ostream = new DataOutputStream(new FileOutputStream(file)) | ||
val content = Array[Byte](0.toByte) | ||
ostream.write(content) | ||
ostream.close() | ||
} | ||
} |