Browse Source

HADOOP-16967. TestSequenceFile#testRecursiveSeqFileCreate fails in subsequent run. Contributed by Ctest.

Ayush Saxena 5 years ago
parent
commit
2ea5adf2de

+ 13 - 7
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSequenceFile.java

@@ -649,8 +649,9 @@ public class TestSequenceFile {
   @Test
   public void testRecursiveSeqFileCreate() throws IOException {
     FileSystem fs = FileSystem.getLocal(conf);
-    Path name = new Path(new Path(GenericTestUtils.getTempPath(
-        "recursiveCreateDir")), "file");
+    Path parentDir = new Path(GenericTestUtils.getTempPath(
+            "recursiveCreateDir"));
+    Path name = new Path(parentDir, "file");
     boolean createParent = false;
 
     try {
@@ -662,11 +663,16 @@ public class TestSequenceFile {
       // Expected
     }
 
-    createParent = true;
-    SequenceFile.createWriter(fs, conf, name, RandomDatum.class,
-        RandomDatum.class, 512, (short) 1, 4096, createParent,
-        CompressionType.NONE, null, new Metadata());
-    // should succeed, fails if exception thrown
+    try {
+      createParent = true;
+      SequenceFile.createWriter(fs, conf, name, RandomDatum.class,
+          RandomDatum.class, 512, (short) 1, 4096, createParent,
+          CompressionType.NONE, null, new Metadata());
+      // should succeed, fails if exception thrown
+    } finally {
+      fs.deleteOnExit(parentDir);
+      fs.close();
+    }
   }
 
   @Test