diff --git a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/testutils/SparkClientFunctionalTestHarness.java b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/testutils/SparkClientFunctionalTestHarness.java index f9676c6c477be..c58dd178dca3a 100644 --- a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/testutils/SparkClientFunctionalTestHarness.java +++ b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/testutils/SparkClientFunctionalTestHarness.java @@ -67,6 +67,7 @@ import org.apache.spark.sql.SQLContext; import org.apache.spark.sql.SparkSession; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; @@ -96,6 +97,7 @@ public class SparkClientFunctionalTestHarness implements SparkProvider, HoodieMe private static transient JavaSparkContext jsc; private static transient HoodieSparkEngineContext context; private static transient TimelineService timelineService; + private FileSystem fileSystem; /** * An indicator of the initialization status. @@ -128,7 +130,10 @@ public Configuration hadoopConf() { } public FileSystem fs() { - return FSUtils.getFs(basePath(), hadoopConf()); + if (fileSystem == null) { + fileSystem = FSUtils.getFs(basePath(), hadoopConf()); + } + return fileSystem; } @Override @@ -208,6 +213,14 @@ public static synchronized void resetSpark() { } } + @AfterEach + public void closeFileSystem() throws IOException { + if (fileSystem != null) { + fileSystem.close(); + fileSystem = null; + } + } + protected JavaRDD tagLocation( HoodieIndex index, JavaRDD records, HoodieTable table) { return HoodieJavaRDD.getJavaRDD(