From 14ae8b80b005c094aaef43e12fd138e81658d1e2 Mon Sep 17 00:00:00 2001 From: ranjanash Date: Sat, 21 Jun 2025 21:48:18 +0530 Subject: [PATCH 1/2] Added retry to release file handler --- .../FSConfigConverterTestCommons.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java index 0e24a10ef26ee..fd5506ef7d46b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java @@ -58,9 +58,32 @@ public FSConfigConverterTestCommons() { public void setUp() throws IOException { File d = new File(TEST_DIR, "conversion-output"); + if (d.exists()) { - FileUtils.deleteDirectory(d); + // Retry mechanism to ensure file handles are released + int maxRetries = 3; + int attempts = 0; + boolean deleted = false; + + while (attempts < maxRetries && !deleted) { + try { + FileUtils.deleteDirectory(d); + deleted = true; + } catch (IOException e) { + attempts++; + System.gc(); // Hint JVM to run GC to close any unreferenced file streams + try { + Thread.sleep(100); // Wait a bit before retrying + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + } + if (attempts == maxRetries) { + throw new IOException("Failed to delete directory after retries: " + d.getAbsolutePath(), e); + } + } + } } + boolean success = d.mkdirs(); assertTrue(success, "Can't create directory: " + d.getAbsolutePath()); } From f9141c6410074ce47e0945277c3d25eaf572c064 Mon Sep 17 00:00:00 2001 From: ranjanash Date: Sat, 28 Jun 2025 13:33:26 +0530 Subject: [PATCH 2/2] Made test directory unique to avoid locking after test cleanup --- .../FSConfigConverterTestCommons.java | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java index fd5506ef7d46b..3f3613320e176 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigConverterTestCommons.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -43,8 +44,7 @@ public class FSConfigConverterTestCommons { new File(TEST_DIR, "test-yarn-site.xml").getAbsolutePath(); public final static String CONVERSION_RULES_FILE = new File(TEST_DIR, "test-conversion-rules.properties").getAbsolutePath(); - public final static String OUTPUT_DIR = - new File(TEST_DIR, "conversion-output").getAbsolutePath(); + public static String OUTPUT_DIR; private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); @@ -57,33 +57,14 @@ public FSConfigConverterTestCommons() { } public void setUp() throws IOException { - File d = new File(TEST_DIR, "conversion-output"); + String uuid = UUID.randomUUID().toString().trim(); + OUTPUT_DIR = + new File(TEST_DIR, "conversion-output" + uuid).getAbsolutePath(); + File d = new File(TEST_DIR, "conversion-output" + uuid); if (d.exists()) { - // Retry mechanism to ensure file handles are released - int maxRetries = 3; - int attempts = 0; - boolean deleted = false; - - while (attempts < maxRetries && !deleted) { - try { - FileUtils.deleteDirectory(d); - deleted = true; - } catch (IOException e) { - attempts++; - System.gc(); // Hint JVM to run GC to close any unreferenced file streams - try { - Thread.sleep(100); // Wait a bit before retrying - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - } - if (attempts == maxRetries) { - throw new IOException("Failed to delete directory after retries: " + d.getAbsolutePath(), e); - } - } - } + FileUtils.deleteDirectory(d); } - boolean success = d.mkdirs(); assertTrue(success, "Can't create directory: " + d.getAbsolutePath()); }