File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
core/src/test/scala/org/apache/spark Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .spark
19
19
20
- import java .io .File
20
+ import java .io .{ File , PrintWriter }
21
21
22
22
import org .scalatest .FunSuite
23
23
@@ -75,6 +75,36 @@ class SparkContextSuite extends FunSuite with LocalSparkContext {
75
75
assert(byteArray2.length === 0 )
76
76
}
77
77
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
+
78
108
test(" addFile recursive works" ) {
79
109
val pluto = new File (" pluto" )
80
110
val neptune = new File (pluto, " neptune" )
You can’t perform that action at this time.
0 commit comments