This is an automated email from the ASF dual-hosted git repository.

yihua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e40cffcc92b fix(hudi-sync): Fix Hive test temp directory cleanup with 
JUnit TempDir (#18883)
6e40cffcc92b is described below

commit 6e40cffcc92b7b6b03410909eee16514c64296d3
Author: fhan <[email protected]>
AuthorDate: Mon Jun 1 06:38:55 2026 +0800

    fix(hudi-sync): Fix Hive test temp directory cleanup with JUnit TempDir 
(#18883)
    
    Co-authored-by: fhan <[email protected]>
---
 .../org/apache/hudi/hive/TestHiveSyncTool.java     | 16 ++++++++++-----
 .../apache/hudi/hive/testutils/HiveTestUtil.java   | 23 +++++++++++++++-------
 .../hudi/utilities/TestHiveIncrementalPuller.java  |  2 +-
 .../apache/hudi/utilities/TestHudiHiveSyncJob.java |  2 +-
 4 files changed, 29 insertions(+), 14 deletions(-)

diff --git 
a/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/TestHiveSyncTool.java
 
b/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/TestHiveSyncTool.java
index ec9d4b0406de..6d971bcc5226 100644
--- 
a/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/TestHiveSyncTool.java
+++ 
b/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/TestHiveSyncTool.java
@@ -67,6 +67,7 @@ import org.junit.jupiter.api.AfterAll;
 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;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.EnumSource;
 import org.junit.jupiter.params.provider.MethodSource;
@@ -75,7 +76,6 @@ import org.junit.jupiter.params.provider.ValueSource;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.nio.file.Files;
-import java.time.Instant;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
@@ -181,6 +181,8 @@ public class TestHiveSyncTool {
 
   private HiveSyncTool hiveSyncTool;
   private HoodieHiveSyncClient hiveClient;
+  @TempDir
+  java.nio.file.Path tempDir;
 
   @AfterAll
   public static void cleanUpClass() throws IOException {
@@ -213,7 +215,7 @@ public class TestHiveSyncTool {
 
   @BeforeEach
   public void setUp() throws Exception {
-    HiveTestUtil.setUp(Option.empty(), true);
+    HiveTestUtil.setUp(Option.empty(), true, tempDir);
   }
 
   @AfterEach
@@ -243,7 +245,7 @@ public class TestHiveSyncTool {
     HiveTestUtil.fileSystem.delete(new Path(basePath), true);
 
     // create a new cow table and reSync
-    basePath = Files.createTempDirectory("hivesynctest" + 
Instant.now().toEpochMilli()).toUri().toString();
+    basePath = createTempBasePath("hivesynctest");
     hiveSyncProps.setProperty(META_SYNC_BASE_PATH.key(), basePath);
     HiveTestUtil.createCOWTable(instantTime, 1, useSchemaFromCommitMetadata);
     reInitHiveSyncClient();
@@ -864,7 +866,7 @@ public class TestHiveSyncTool {
 
     String commitTime2 = "105";
     // let's update the basepath
-    basePath = Files.createTempDirectory("hivesynctest_new" + 
Instant.now().toEpochMilli()).toUri().toString();
+    basePath = createTempBasePath("hivesynctest-new");
     hiveSyncProps.setProperty(META_SYNC_BASE_PATH.key(), basePath);
 
     // let's create new table in new basepath
@@ -1116,7 +1118,7 @@ public class TestHiveSyncTool {
     reSyncHiveTable();
 
     // change the hoodie base path
-    basePath = Files.createTempDirectory("hivesynctest_new" + 
Instant.now().toEpochMilli()).toUri().toString();
+    basePath = createTempBasePath("hivesynctest-new");
     hiveSyncProps.setProperty(META_SYNC_BASE_PATH.key(), basePath);
 
     String instantTime2 = "102";
@@ -2268,6 +2270,10 @@ public class TestHiveSyncTool {
     hiveClient = (HoodieHiveSyncClient) hiveSyncTool.syncClient;
   }
 
+  private String createTempBasePath(String prefix) throws IOException {
+    return Files.createTempDirectory(tempDir, prefix).toUri().toString();
+  }
+
   private int getPartitionFieldSize() {
     return 
hiveSyncProps.getString(META_SYNC_PARTITION_FIELDS.key()).split(",").length;
   }
diff --git 
a/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/testutils/HiveTestUtil.java
 
b/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/testutils/HiveTestUtil.java
index 4d75ca0e6b42..24e76b2d9f69 100644
--- 
a/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/testutils/HiveTestUtil.java
+++ 
b/hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/testutils/HiveTestUtil.java
@@ -85,7 +85,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URISyntaxException;
 import java.nio.file.Files;
-import java.time.Instant;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
@@ -140,6 +139,11 @@ public class HiveTestUtil {
   private static Set<String> createdTablesSet = new HashSet<>();
 
   public static void setUp(Option<TypedProperties> hiveSyncProperties, boolean 
shouldClearBasePathAndTables) throws Exception {
+    setUp(hiveSyncProperties, shouldClearBasePathAndTables, null);
+  }
+
+  public static void setUp(Option<TypedProperties> hiveSyncProperties, boolean 
shouldClearBasePathAndTables,
+                           java.nio.file.Path tempDir) throws Exception {
     configuration = new Configuration();
     if (zkServer == null) {
       zkService = new ZookeeperTestService(configuration);
@@ -155,7 +159,10 @@ public class HiveTestUtil {
       hiveSyncProps.setProperty(HIVE_URL.key(), 
hiveTestService.getJdbcHive2Url());
       basePath = hiveSyncProps.getProperty(META_SYNC_BASE_PATH.key());
     } else {
-      basePath = Files.createTempDirectory("hivesynctest" + 
Instant.now().toEpochMilli()).toUri().toString();
+      java.nio.file.Path baseDir = tempDir == null
+          ? Files.createTempDirectory("hivesynctest")
+          : Files.createTempDirectory(Files.createDirectories(tempDir), 
"hivesynctest");
+      basePath = baseDir.toUri().toString();
 
       hiveSyncProps = new TypedProperties();
       hiveSyncProps.setProperty(HIVE_URL.key(), 
hiveTestService.getJdbcHive2Url());
@@ -183,15 +190,17 @@ public class HiveTestUtil {
     if (shouldClearBasePathAndTables) {
       clear();
     }
+    if (!hiveSyncProperties.isPresent()) {
+      HoodieTableMetaClient.newTableBuilder()
+          .setTableType(HoodieTableType.COPY_ON_WRITE)
+          .setTableName(TABLE_NAME)
+          .setPayloadClass(HoodieAvroPayload.class)
+          .initTable(HadoopFSUtils.getStorageConfWithCopy(configuration), 
basePath);
+    }
   }
 
   public static void clear() throws IOException, HiveException, MetaException {
     fileSystem.delete(new Path(basePath), true);
-    HoodieTableMetaClient.newTableBuilder()
-        .setTableType(HoodieTableType.COPY_ON_WRITE)
-        .setTableName(TABLE_NAME)
-        .setPayloadClass(HoodieAvroPayload.class)
-        .initTable(HadoopFSUtils.getStorageConfWithCopy(configuration), 
basePath);
 
     if (ddlExecutor != null) {
       for (String tableName : createdTablesSet) {
diff --git 
a/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHiveIncrementalPuller.java
 
b/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHiveIncrementalPuller.java
index 42e0ee874863..5bfb6933fdc6 100644
--- 
a/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHiveIncrementalPuller.java
+++ 
b/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHiveIncrementalPuller.java
@@ -67,7 +67,7 @@ public class TestHiveIncrementalPuller {
 
   @BeforeEach
   public void setUp() throws Exception {
-    HiveTestUtil.setUp(Option.empty(), true);
+    HiveTestUtil.setUp(Option.empty(), true, tempDir);
   }
 
   @AfterEach
diff --git 
a/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHudiHiveSyncJob.java
 
b/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHudiHiveSyncJob.java
index 64abaf68a8db..0099eaebbf39 100644
--- 
a/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHudiHiveSyncJob.java
+++ 
b/hudi-utilities/src/test/java/org/apache/hudi/utilities/TestHudiHiveSyncJob.java
@@ -67,7 +67,7 @@ public class TestHudiHiveSyncJob {
 
   @BeforeEach
   void setUp() throws Exception {
-    HiveTestUtil.setUp(Option.empty(), true);
+    HiveTestUtil.setUp(Option.empty(), true, tempDir);
   }
 
   @AfterEach

Reply via email to