Skip to content

Commit ca83849

Browse files
committed
Add addFile test
1 parent 1941be3 commit ca83849

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark
1919

20-
import java.io.File
20+
import java.io.{File, PrintWriter}
2121

2222
import org.scalatest.FunSuite
2323

@@ -75,6 +75,36 @@ class SparkContextSuite extends FunSuite with LocalSparkContext {
7575
assert(byteArray2.length === 0)
7676
}
7777

78+
test("addFile works") {
79+
val file = new File("somefile")
80+
val absolutePath = file.getAbsolutePath
81+
try {
82+
val pw = new PrintWriter(file)
83+
pw.print("somewords")
84+
pw.close()
85+
val length = file.length()
86+
sc = new SparkContext(new SparkConf().setAppName("test").setMaster("local"))
87+
sc.addFile(file.getAbsolutePath)
88+
sc.parallelize(Array(1), 1).map(x => {
89+
val gotten = new File(SparkFiles.get(file.getName))
90+
if (!gotten.exists()) {
91+
throw new SparkException("file doesn't exist")
92+
}
93+
if (length != gotten.length()) {
94+
throw new SparkException(
95+
s"file has different length $length than added file ${gotten.length()}")
96+
}
97+
if (absolutePath == gotten.getAbsolutePath) {
98+
throw new SparkException("file should have been copied")
99+
}
100+
x
101+
}).count()
102+
} finally {
103+
sc.stop()
104+
file.delete()
105+
}
106+
}
107+
78108
test("addFile recursive works") {
79109
val pluto = new File("pluto")
80110
val neptune = new File(pluto, "neptune")

0 commit comments

Comments
 (0)