Skip to content

Commit 10492a0

Browse files
committed
[SPARK-53118][CORE][TESTS] Use Files.write in GenericFileInputStreamSuite
### What changes were proposed in this pull request? This PR aims to use `Files.write` instead of `FileUtils.writeByteArrayToFile` in the abstract test suite `GenericFileInputStreamSuite`. This will be used in the following two test cases. - org.apache.spark.io.GenericFileInputStreamSuite - org.apache.spark.io.NioBufferedInputStreamSuite - org.apache.spark.io.ReadAheadInputStreamSuite ### Why are the changes needed? This is the only place to use `FileUtils.writeByteArrayToFile` to write **2MB** byte array to generate a test input file. We had better use Java's native method for small test data usage. https://github.com/apache/spark/blob/50882d2d88866ef0747ab7b542ac8ebaab4418ae/core/src/test/java/org/apache/spark/io/GenericFileInputStreamSuite.java#L37 ### Does this PR introduce _any_ user-facing change? This is a test only change. ### How was this patch tested? Pass the CIs. **BEFORE** ``` $ git grep FileUtils.writeByteArrayToFile core/src/test/java/org/apache/spark/io/GenericFileInputStreamSuite.java: FileUtils.writeByteArrayToFile(inputFile, randomBytes); ``` **AFTER** ``` $ git grep FileUtils.writeByteArrayToFile ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51837 from dongjoon-hyun/SPARK-53118. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 93fc2ed commit 10492a0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

core/src/test/java/org/apache/spark/io/GenericFileInputStreamSuite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
*/
1717
package org.apache.spark.io;
1818

19-
import org.apache.commons.io.FileUtils;
2019
import org.junit.jupiter.api.AfterEach;
2120
import org.junit.jupiter.api.BeforeEach;
2221
import org.junit.jupiter.api.Test;
2322

2423
import java.io.File;
2524
import java.io.IOException;
2625
import java.io.InputStream;
26+
import java.nio.file.Files;
2727
import java.util.concurrent.ThreadLocalRandom;
2828

2929
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -44,7 +44,7 @@ public abstract class GenericFileInputStreamSuite {
4444
public void setUp() throws IOException {
4545
ThreadLocalRandom.current().nextBytes(randomBytes);
4646
inputFile = File.createTempFile("temp-file", ".tmp");
47-
FileUtils.writeByteArrayToFile(inputFile, randomBytes);
47+
Files.write(inputFile.toPath(), randomBytes);
4848
}
4949

5050
@AfterEach

0 commit comments

Comments
 (0)