llama90 commented on code in PR #42093:
URL: https://github.com/apache/arrow/pull/42093#discussion_r1634219170
##########
java/tools/src/test/java/org/apache/arrow/tools/TestFileRoundtrip.java:
##########
@@ -18,40 +18,46 @@
import static org.apache.arrow.tools.ArrowFileTestFixtures.validateOutput;
import static org.apache.arrow.tools.ArrowFileTestFixtures.writeInput;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
+import java.io.IOException;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class TestFileRoundtrip {
- @Rule public TemporaryFolder testFolder = new TemporaryFolder();
+ @TempDir public File testFolder;
private BufferAllocator allocator;
- @Before
+ @BeforeEach
public void init() {
allocator = new RootAllocator(Integer.MAX_VALUE);
}
- @After
+ @AfterEach
public void tearDown() {
allocator.close();
}
@Test
public void test() throws Exception {
- File testInFile = testFolder.newFile("testIn.arrow");
- File testOutFile = testFolder.newFile("testOut.arrow");
+ File testInFile = new File(testFolder, "testIn.arrow");
+ File testOutFile = new File(testFolder, "testOut.arrow");
writeInput(testInFile, allocator);
+ if (!testOutFile.exists()) {
+ if (!testOutFile.createNewFile()) {
Review Comment:
> Can you check with a Thread.sleep or something and see if it doesn't occur?
`Thread.sleep` does not resolve this problem.
> I am not sure what is the annotated `File` is doing here, is
`createNewFile` a mandatory call otherwise?
The annotated `File` is ready for test the `FileRoundtrip`. I think the
`FileRoundtrip` needs created paths for input and output. After changing the
annotation from JUnit 4 to JUnit 5, it cannot find the output directory.
The input directory is created with the `writeInput` method. However, the
output is not created until calling `validateFile` of `FileRoundtrip.run`.
https://github.com/apache/arrow/blob/4df00fa477b555139b06288b3d15b81cf701c518/java/tools/src/test/java/org/apache/arrow/tools/ArrowFileTestFixtures.java#L89-L98
I guess that occurs by the difference between `@TemporaryFolder` (JUnit 4)
and `@TempDir` (JUnit 5). `@TempDir` just manages the lifecycle of the
temporary directory in the `Test` methods <del>class</del>.
_**`@TempDir` objects do not cause errors if they are only used within the
`Test` methods <del>class</del>**_ (It seems that previously migrated tests did
not have such cases).
I think we have two approaches.
1. Explicitly call `createNewFile` to create the temp directory.
2. Modify the `validateFile` method of the `FileRoundtrip` class to create
the directory when called.
I am looking into the basis for my thoughts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]