Skip to content

Commit 0ff3fa8

Browse files
committed
test for add file
1 parent dced8eb commit 0ff3fa8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

core/src/test/scala/org/apache/spark/SparkContextSuite.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ class SparkContextSuite extends FunSuite with LocalSparkContext {
106106
sc.stop()
107107
}
108108
}
109+
110+
test("addFile works with relative path") {
111+
val pluto = Utils.createTempDir()
112+
val file = File.createTempFile("someprefix", "somesuffix", pluto)
113+
val relativePath = file.getParent + "/../" + file.getParentFile.getName + "/" + file.getName
114+
val absolutePath = file.getAbsolutePath
115+
try {
116+
Files.write("somewords", file, UTF_8)
117+
val length = file.length()
118+
sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local"))
119+
sc.addFile(relativePath)
120+
sc.parallelize(Array(1), 1).map(x => {
121+
val gotten = new File(SparkFiles.get(file.getName))
122+
if (!gotten.exists()) {
123+
throw new SparkException("file doesn't exist")
124+
}
125+
if (length != gotten.length()) {
126+
throw new SparkException(
127+
s"file has different length $length than added file ${gotten.length()}")
128+
}
129+
if (absolutePath == gotten.getAbsolutePath) {
130+
throw new SparkException("file should have been copied")
131+
}
132+
x
133+
}).count()
134+
} finally {
135+
sc.stop()
136+
}
137+
}
109138

110139
test("addFile recursive works") {
111140
val pluto = Utils.createTempDir()

0 commit comments

Comments
 (0)