Skip to content
Snippets Groups Projects
Commit 6657e00d authored by liuxian's avatar liuxian Committed by Wenchen Fan
Browse files

[SPARK-21283][CORE] FileOutputStream should be created as append mode

## What changes were proposed in this pull request?

`FileAppender` is used to write `stderr` and `stdout` files  in `ExecutorRunner`, But before writing `ErrorStream` into the the `stderr` file, the header information has been written into ,if  FileOutputStream is  not created as append mode, the  header information will be lost

## How was this patch tested?
unit test case

Author: liuxian <liu.xian3@zte.com.cn>

Closes #18507 from 10110346/wip-lx-0703.
parent c79c10eb
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ private[spark] class FileAppender(inputStream: InputStream, file: File, bufferSi
/** Open the file output stream */
protected def openFile() {
outputStream = new FileOutputStream(file, false)
outputStream = new FileOutputStream(file, true)
logDebug(s"Opened file $file")
}
......
......@@ -52,10 +52,13 @@ class FileAppenderSuite extends SparkFunSuite with BeforeAndAfter with Logging {
test("basic file appender") {
val testString = (1 to 1000).mkString(", ")
val inputStream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8))
// The `header` should not be covered
val header = "Add header"
Files.write(header, testFile, StandardCharsets.UTF_8)
val appender = new FileAppender(inputStream, testFile)
inputStream.close()
appender.awaitTermination()
assert(Files.toString(testFile, StandardCharsets.UTF_8) === testString)
assert(Files.toString(testFile, StandardCharsets.UTF_8) === header + testString)
}
test("rolling file appender - time-based rolling") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment