Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit ca00cc7

Browse files
heary-caosrowen
authored andcommitted
[SPARK-21963][CORE][TEST] Create temp file should be delete after use
## What changes were proposed in this pull request? After you create a temporary table, you need to delete it, otherwise it will leave a file similar to the file name ‘SPARK194465907929586320484966temp’. ## How was this patch tested? N / A Author: caoxuewen <[email protected]> Closes apache#19174 from heary-cao/DeleteTempFile.
1 parent 4fbf748 commit ca00cc7

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ class SparkContextSuite extends SparkFunSuite with LocalSparkContext with Eventu
600600
val fs = new DebugFilesystem()
601601
fs.initialize(new URI("file:///"), new Configuration())
602602
val file = File.createTempFile("SPARK19446", "temp")
603+
file.deleteOnExit()
603604
Files.write(Array.ofDim[Byte](1000), file)
604605
val path = new Path("file:///" + file.getCanonicalPath)
605606
val stream = fs.open(path)

core/src/test/scala/org/apache/spark/security/CryptoStreamUtilsSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class CryptoStreamUtilsSuite extends SparkFunSuite {
130130
val conf = createConf()
131131
val key = createKey(conf)
132132
val file = Files.createTempFile("crypto", ".test").toFile()
133+
file.deleteOnExit()
133134

134135
val outStream = createCryptoOutputStream(new FileOutputStream(file), conf, key)
135136
try {

core/src/test/scala/org/apache/spark/util/UtilsSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ class UtilsSuite extends SparkFunSuite with ResetSystemProperties with Logging {
939939
// creating a very misbehaving process. It ignores SIGTERM and has been SIGSTOPed. On
940940
// older versions of java, this will *not* terminate.
941941
val file = File.createTempFile("temp-file-name", ".tmp")
942+
file.deleteOnExit()
942943
val cmd =
943944
s"""
944945
|#!/bin/bash

launcher/src/test/java/org/apache/spark/launcher/ChildProcAppHandleSuite.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public void testRedirectErrorToLog() throws Exception {
114114
assumeFalse(isWindows());
115115

116116
Path err = Files.createTempFile("stderr", "txt");
117+
err.toFile().deleteOnExit();
117118

118119
SparkAppHandle handle = (ChildProcAppHandle) new TestSparkLauncher()
119120
.redirectError(err.toFile())
@@ -129,6 +130,7 @@ public void testRedirectOutputToLog() throws Exception {
129130
assumeFalse(isWindows());
130131

131132
Path out = Files.createTempFile("stdout", "txt");
133+
out.toFile().deleteOnExit();
132134

133135
SparkAppHandle handle = (ChildProcAppHandle) new TestSparkLauncher()
134136
.redirectOutput(out.toFile())
@@ -145,6 +147,8 @@ public void testNoRedirectToLog() throws Exception {
145147

146148
Path out = Files.createTempFile("stdout", "txt");
147149
Path err = Files.createTempFile("stderr", "txt");
150+
out.toFile().deleteOnExit();
151+
err.toFile().deleteOnExit();
148152

149153
ChildProcAppHandle handle = (ChildProcAppHandle) new TestSparkLauncher()
150154
.redirectError(err.toFile())
@@ -159,19 +163,23 @@ public void testNoRedirectToLog() throws Exception {
159163

160164
@Test(expected = IllegalArgumentException.class)
161165
public void testBadLogRedirect() throws Exception {
166+
File out = Files.createTempFile("stdout", "txt").toFile();
167+
out.deleteOnExit();
162168
new SparkLauncher()
163169
.redirectError()
164-
.redirectOutput(Files.createTempFile("stdout", "txt").toFile())
170+
.redirectOutput(out)
165171
.redirectToLog("foo")
166172
.launch()
167173
.waitFor();
168174
}
169175

170176
@Test(expected = IllegalArgumentException.class)
171177
public void testRedirectErrorTwiceFails() throws Exception {
178+
File err = Files.createTempFile("stderr", "txt").toFile();
179+
err.deleteOnExit();
172180
new SparkLauncher()
173181
.redirectError()
174-
.redirectError(Files.createTempFile("stderr", "txt").toFile())
182+
.redirectError(err)
175183
.launch()
176184
.waitFor();
177185
}
@@ -180,6 +188,7 @@ public void testRedirectErrorTwiceFails() throws Exception {
180188
public void testProcMonitorWithOutputRedirection() throws Exception {
181189
assumeFalse(isWindows());
182190
File err = Files.createTempFile("out", "txt").toFile();
191+
err.deleteOnExit();
183192
SparkAppHandle handle = new TestSparkLauncher()
184193
.redirectError()
185194
.redirectOutput(err)

0 commit comments

Comments
 (0)