Skip to content

Commit b30a11a

Browse files
committed
[SPARK-21764][TESTS] Fix tests failures on Windows: resources not being closed and incorrect paths
## What changes were proposed in this pull request? `org.apache.spark.deploy.RPackageUtilsSuite` ``` - jars without manifest return false *** FAILED *** (109 milliseconds) java.io.IOException: Unable to delete file: C:\projects\spark\target\tmp\1500266936418-0\dep1-c.jar ``` `org.apache.spark.deploy.SparkSubmitSuite` ``` - download one file to local *** FAILED *** (16 milliseconds) java.net.URISyntaxException: Illegal character in authority at index 6: s3a://C:\projects\spark\target\tmp\test2630198944759847458.jar - download list of files to local *** FAILED *** (0 milliseconds) java.net.URISyntaxException: Illegal character in authority at index 6: s3a://C:\projects\spark\target\tmp\test2783551769392880031.jar ``` `org.apache.spark.scheduler.ReplayListenerSuite` ``` - Replay compressed inprogress log file succeeding on partial read (156 milliseconds) Exception encountered when attempting to run a suite with class name: org.apache.spark.scheduler.ReplayListenerSuite *** ABORTED *** (1 second, 391 milliseconds) java.io.IOException: Failed to delete: C:\projects\spark\target\tmp\spark-8f3cacd6-faad-4121-b901-ba1bba8025a0 - End-to-end replay *** FAILED *** (62 milliseconds) java.io.IOException: No FileSystem for scheme: C - End-to-end replay with compression *** FAILED *** (110 milliseconds) java.io.IOException: No FileSystem for scheme: C ``` `org.apache.spark.sql.hive.StatisticsSuite` ``` - SPARK-21079 - analyze table with location different than that of individual partitions *** FAILED *** (875 milliseconds) org.apache.spark.sql.AnalysisException: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:java.lang.IllegalArgumentException: Can not create a Path from an empty string); - SPARK-21079 - analyze partitioned table with only a subset of partitions visible *** FAILED *** (47 milliseconds) org.apache.spark.sql.AnalysisException: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:java.lang.IllegalArgumentException: Can not create a Path from an empty string); ``` **Note:** this PR does not fix: `org.apache.spark.deploy.SparkSubmitSuite` ``` - launch simple application with spark-submit with redaction *** FAILED *** (172 milliseconds) java.util.NoSuchElementException: next on empty iterator ``` I can't reproduce this on my Windows machine but looks appearntly consistently failed on AppVeyor. This one is unclear to me yet and hard to debug so I did not include this one for now. **Note:** it looks there are more instances but it is hard to identify them partly due to flakiness and partly due to swarming logs and errors. Will probably go one more time if it is fine. ## How was this patch tested? Manually via AppVeyor: **Before** - `org.apache.spark.deploy.RPackageUtilsSuite`: https://ci.appveyor.com/project/spark-test/spark/build/771-windows-fix/job/8t8ra3lrljuir7q4 - `org.apache.spark.deploy.SparkSubmitSuite`: https://ci.appveyor.com/project/spark-test/spark/build/771-windows-fix/job/taquy84yudjjen64 - `org.apache.spark.scheduler.ReplayListenerSuite`: https://ci.appveyor.com/project/spark-test/spark/build/771-windows-fix/job/24omrfn2k0xfa9xq - `org.apache.spark.sql.hive.StatisticsSuite`: https://ci.appveyor.com/project/spark-test/spark/build/771-windows-fix/job/2079y1plgj76dc9l **After** - `org.apache.spark.deploy.RPackageUtilsSuite`: https://ci.appveyor.com/project/spark-test/spark/build/775-windows-fix/job/3803dbfn89ne1164 - `org.apache.spark.deploy.SparkSubmitSuite`: https://ci.appveyor.com/project/spark-test/spark/build/775-windows-fix/job/m5l350dp7u9a4xjr - `org.apache.spark.scheduler.ReplayListenerSuite`: https://ci.appveyor.com/project/spark-test/spark/build/775-windows-fix/job/565vf74pp6bfdk18 - `org.apache.spark.sql.hive.StatisticsSuite`: https://ci.appveyor.com/project/spark-test/spark/build/775-windows-fix/job/qm78tsk8c37jb6s4 Jenkins tests are required and AppVeyor tests will be triggered. Author: hyukjinkwon <[email protected]> Closes apache#18971 from HyukjinKwon/windows-fixes.
1 parent 734ed7a commit b30a11a

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

core/src/test/scala/org/apache/spark/deploy/RPackageUtilsSuite.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ class RPackageUtilsSuite
137137
IvyTestUtils.withRepository(main, None, None) { repo =>
138138
val jar = IvyTestUtils.packJar(new File(new URI(repo)), dep1, Nil,
139139
useIvyLayout = false, withR = false, None)
140-
val jarFile = new JarFile(jar)
141-
assert(jarFile.getManifest == null, "jar file should have null manifest")
142-
assert(!RPackageUtils.checkManifestForR(jarFile), "null manifest should return false")
140+
Utils.tryWithResource(new JarFile(jar)) { jarFile =>
141+
assert(jarFile.getManifest == null, "jar file should have null manifest")
142+
assert(!RPackageUtils.checkManifestForR(jarFile), "null manifest should return false")
143+
}
143144
}
144145
}
145146

core/src/test/scala/org/apache/spark/deploy/SparkSubmitSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ class SparkSubmitSuite
831831
val hadoopConf = new Configuration()
832832
val tmpDir = Files.createTempDirectory("tmp").toFile
833833
updateConfWithFakeS3Fs(hadoopConf)
834-
val sourcePath = s"s3a://${jarFile.getAbsolutePath}"
834+
val sourcePath = s"s3a://${jarFile.toURI.getPath}"
835835
val outputPath = DependencyUtils.downloadFile(sourcePath, tmpDir, sparkConf, hadoopConf,
836836
new SecurityManager(sparkConf))
837837
checkDownloadedFile(sourcePath, outputPath)
@@ -847,7 +847,7 @@ class SparkSubmitSuite
847847
val hadoopConf = new Configuration()
848848
val tmpDir = Files.createTempDirectory("tmp").toFile
849849
updateConfWithFakeS3Fs(hadoopConf)
850-
val sourcePaths = Seq("/local/file", s"s3a://${jarFile.getAbsolutePath}")
850+
val sourcePaths = Seq("/local/file", s"s3a://${jarFile.toURI.getPath}")
851851
val outputPaths = DependencyUtils
852852
.downloadFileList(sourcePaths.mkString(","), tmpDir, sparkConf, hadoopConf,
853853
new SecurityManager(sparkConf))

core/src/test/scala/org/apache/spark/scheduler/ReplayListenerSuite.scala

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.io._
2121
import java.net.URI
2222
import java.util.concurrent.atomic.AtomicInteger
2323

24+
import org.apache.hadoop.fs.Path
2425
import org.json4s.jackson.JsonMethods._
2526
import org.scalatest.BeforeAndAfter
2627

@@ -84,24 +85,23 @@ class ReplayListenerSuite extends SparkFunSuite with BeforeAndAfter with LocalSp
8485
val buffered = new ByteArrayOutputStream
8586
val codec = new LZ4CompressionCodec(new SparkConf())
8687
val compstream = codec.compressedOutputStream(buffered)
87-
val writer = new PrintWriter(compstream)
88+
Utils.tryWithResource(new PrintWriter(compstream)) { writer =>
8889

89-
val applicationStart = SparkListenerApplicationStart("AppStarts", None,
90-
125L, "Mickey", None)
91-
val applicationEnd = SparkListenerApplicationEnd(1000L)
90+
val applicationStart = SparkListenerApplicationStart("AppStarts", None,
91+
125L, "Mickey", None)
92+
val applicationEnd = SparkListenerApplicationEnd(1000L)
9293

93-
// scalastyle:off println
94-
writer.println(compact(render(JsonProtocol.sparkEventToJson(applicationStart))))
95-
writer.println(compact(render(JsonProtocol.sparkEventToJson(applicationEnd))))
96-
// scalastyle:on println
97-
writer.close()
94+
// scalastyle:off println
95+
writer.println(compact(render(JsonProtocol.sparkEventToJson(applicationStart))))
96+
writer.println(compact(render(JsonProtocol.sparkEventToJson(applicationEnd))))
97+
// scalastyle:on println
98+
}
9899

99100
val logFilePath = Utils.getFilePath(testDir, "events.lz4.inprogress")
100-
val fstream = fileSystem.create(logFilePath)
101101
val bytes = buffered.toByteArray
102-
103-
fstream.write(bytes, 0, buffered.size)
104-
fstream.close
102+
Utils.tryWithResource(fileSystem.create(logFilePath)) { fstream =>
103+
fstream.write(bytes, 0, buffered.size)
104+
}
105105

106106
// Read the compressed .inprogress file and verify only first event was parsed.
107107
val conf = EventLoggingListenerSuite.getLoggingConf(logFilePath)
@@ -112,17 +112,19 @@ class ReplayListenerSuite extends SparkFunSuite with BeforeAndAfter with LocalSp
112112

113113
// Verify the replay returns the events given the input maybe truncated.
114114
val logData = EventLoggingListener.openEventLog(logFilePath, fileSystem)
115-
val failingStream = new EarlyEOFInputStream(logData, buffered.size - 10)
116-
replayer.replay(failingStream, logFilePath.toString, true)
115+
Utils.tryWithResource(new EarlyEOFInputStream(logData, buffered.size - 10)) { failingStream =>
116+
replayer.replay(failingStream, logFilePath.toString, true)
117117

118-
assert(eventMonster.loggedEvents.size === 1)
119-
assert(failingStream.didFail)
118+
assert(eventMonster.loggedEvents.size === 1)
119+
assert(failingStream.didFail)
120+
}
120121

121122
// Verify the replay throws the EOF exception since the input may not be truncated.
122123
val logData2 = EventLoggingListener.openEventLog(logFilePath, fileSystem)
123-
val failingStream2 = new EarlyEOFInputStream(logData2, buffered.size - 10)
124-
intercept[EOFException] {
125-
replayer.replay(failingStream2, logFilePath.toString, false)
124+
Utils.tryWithResource(new EarlyEOFInputStream(logData2, buffered.size - 10)) { failingStream2 =>
125+
intercept[EOFException] {
126+
replayer.replay(failingStream2, logFilePath.toString, false)
127+
}
126128
}
127129
}
128130

@@ -151,7 +153,10 @@ class ReplayListenerSuite extends SparkFunSuite with BeforeAndAfter with LocalSp
151153
* assumption that the event logging behavior is correct (tested in a separate suite).
152154
*/
153155
private def testApplicationReplay(codecName: Option[String] = None) {
154-
val logDirPath = Utils.getFilePath(testDir, "test-replay")
156+
val logDir = new File(testDir.getAbsolutePath, "test-replay")
157+
// Here, it creates `Path` from the URI instead of the absolute path for the explicit file
158+
// scheme so that the string representation of this `Path` has leading file scheme correctly.
159+
val logDirPath = new Path(logDir.toURI)
155160
fileSystem.mkdirs(logDirPath)
156161

157162
val conf = EventLoggingListenerSuite.getLoggingConf(logDirPath, codecName)
@@ -221,12 +226,14 @@ class ReplayListenerSuite extends SparkFunSuite with BeforeAndAfter with LocalSp
221226
def didFail: Boolean = countDown.get == 0
222227

223228
@throws[IOException]
224-
def read: Int = {
229+
override def read(): Int = {
225230
if (countDown.get == 0) {
226231
throw new EOFException("Stream ended prematurely")
227232
}
228233
countDown.decrementAndGet()
229-
in.read
234+
in.read()
230235
}
236+
237+
override def close(): Unit = in.close()
231238
}
232239
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/StatisticsSuite.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class StatisticsSuite extends StatisticsCollectionTestBase with TestHiveSingleto
203203
sql(s"INSERT INTO TABLE $tableName PARTITION (ds='$ds') SELECT * FROM src")
204204
}
205205

206-
sql(s"ALTER TABLE $tableName SET LOCATION '$path'")
206+
sql(s"ALTER TABLE $tableName SET LOCATION '${path.toURI}'")
207207

208208
sql(s"ANALYZE TABLE $tableName COMPUTE STATISTICS noscan")
209209

@@ -222,7 +222,7 @@ class StatisticsSuite extends StatisticsCollectionTestBase with TestHiveSingleto
222222
s"""
223223
|CREATE TABLE $sourceTableName (key STRING, value STRING)
224224
|PARTITIONED BY (ds STRING)
225-
|LOCATION '$path'
225+
|LOCATION '${path.toURI}'
226226
""".stripMargin)
227227

228228
val partitionDates = List("2010-01-01", "2010-01-02", "2010-01-03")
@@ -239,7 +239,7 @@ class StatisticsSuite extends StatisticsCollectionTestBase with TestHiveSingleto
239239
s"""
240240
|CREATE TABLE $tableName (key STRING, value STRING)
241241
|PARTITIONED BY (ds STRING)
242-
|LOCATION '$path'
242+
|LOCATION '${path.toURI}'
243243
""".stripMargin)
244244

245245
// Register only one of the partitions found on disk

0 commit comments

Comments
 (0)