Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing tests #276

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ class S3FileManagerTests extends FunSpec with BeforeAndAfterAll with Suite {
assert(fileList.head.fileName == "data.txt")
assert(fileList.head.size == fileData.length)

// Fail to get a file listing
val listingException = intercept[FileNotFoundException] {
fileManager.getFileListing("/missing-directory")
}
assert(listingException.getMessage.startsWith("Path not found when attempting to get listing,inputPath="))
// Rename the file
assert(!fileManager.exists(file1))
assert(fileManager.rename(file, file1))
Expand All @@ -98,7 +93,6 @@ class S3FileManagerTests extends FunSpec with BeforeAndAfterAll with Suite {
val root = s"s3://$bucketName/recursive"
val f1 = new PrintWriter(fileManager.getOutputStream(s"$root/f1.txt"))
f1.print("file1")
f1.flush()
f1.close()
val f2 = new PrintWriter(fileManager.getOutputStream(s"$root/dir1/f2.txt"))
f2.print("file2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ class FileManagerTests extends FunSpec with Suite {
}

it("Should respect the recursive listing flag") {
val testDir = Files.createTempDirectory("recursiveTest")
val fileManager = FileManager()
val root = s"${testDirectory.toAbsolutePath.toString}/recursive"
val root = s"${testDir.toAbsolutePath.toString}/recursive"
new File(root).mkdir()
new File(s"$root/dir1").mkdir()
new File(s"$root/dir1/dir2").mkdir()
Expand All @@ -115,18 +116,20 @@ class FileManagerTests extends FunSpec with Suite {
assert(listing.size == 3)
val expected = List("f1.txt", "f2.txt", "f3.txt")
assert(listing.map(_.fileName).forall(expected.contains))
fileManager.deleteFile(testDir.toAbsolutePath.toString)
}
}

describe("FileManager - HDFS") {
// set up mini hadoop cluster
val testDirectory = Files.createTempDirectory("hdfsFileManagerTests")
val config = new HdfsConfiguration()
config.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, testDirectory.toFile.getAbsolutePath)
val miniCluster = new MiniDFSCluster.Builder(config).build()
miniCluster.waitActive()
val fs = miniCluster.getFileSystem

it("Should perform proper file operations against a HDFS file system") {
val testDirectory = Files.createTempDirectory("hdfsFileManagerTests")
val config = new HdfsConfiguration()
config.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, testDirectory.toFile.getAbsolutePath)
val miniCluster = new MiniDFSCluster.Builder(config).build()
miniCluster.waitActive()
val fs = miniCluster.getFileSystem
val conf = new SparkConf()
.setMaster("local")
.set("spark.hadoop.fs.defaultFS", miniCluster.getFileSystem().getUri.toString)
Expand Down Expand Up @@ -218,14 +221,18 @@ class FileManagerTests extends FunSpec with Suite {
}

it("Should respect the recursive listing flag") {
val testDirectory = Files.createTempDirectory("hdfsRecursive")
val config = new HdfsConfiguration()
config.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, testDirectory.toFile.getAbsolutePath)
val miniCluster = new MiniDFSCluster.Builder(config).build()
miniCluster.waitActive()
val conf = new SparkConf()
.setMaster("local")
.set("spark.hadoop.fs.defaultFS", miniCluster.getFileSystem().getUri.toString)
val fileManager = HDFSFileManager(conf)
val root = s"/recursive"
val f1 = new PrintWriter(fileManager.getOutputStream(s"$root/f1.txt"))
f1.print("file1")
f1.flush()
f1.close()
val f2 = new PrintWriter(fileManager.getOutputStream(s"$root/dir1/f2.txt"))
f2.print("file2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class GCSFileManagerTests extends FunSpec with Suite {
val root = s"/recursive"
val f1 = new PrintWriter(fileManager.getOutputStream(s"$root/f1.txt"))
f1.print("file1")
f1.flush()
f1.close()
val f2 = new PrintWriter(fileManager.getOutputStream(s"$root/dir1/f2.txt"))
f2.print("file2")
Expand Down