From d229bfb8bd1dec5dd51202265e35342b7041c9e1 Mon Sep 17 00:00:00 2001 From: Zouxxyy Date: Mon, 26 Sep 2022 12:28:55 +0800 Subject: [PATCH] [HUDI-4830] Fix testNoGlobalConfFileConfigured when add hudi-defaults.conf in default dir (#6652) --- .../common/util/TestDFSPropertiesConfiguration.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hudi-common/src/test/java/org/apache/hudi/common/util/TestDFSPropertiesConfiguration.java b/hudi-common/src/test/java/org/apache/hudi/common/util/TestDFSPropertiesConfiguration.java index 465739340dc8..73d10d73d2f7 100644 --- a/hudi-common/src/test/java/org/apache/hudi/common/util/TestDFSPropertiesConfiguration.java +++ b/hudi-common/src/test/java/org/apache/hudi/common/util/TestDFSPropertiesConfiguration.java @@ -18,13 +18,16 @@ package org.apache.hudi.common.util; +import org.apache.hadoop.conf.Configuration; import org.apache.hudi.common.config.DFSPropertiesConfiguration; import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.fs.FSUtils; import org.apache.hudi.common.testutils.minicluster.HdfsTestService; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.apache.hudi.exception.HoodieIOException; import org.junit.Rule; import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.jupiter.api.AfterAll; @@ -171,9 +174,14 @@ public void testLocalFileSystemLoading() throws IOException { @Test public void testNoGlobalConfFileConfigured() { ENVIRONMENT_VARIABLES.clear(DFSPropertiesConfiguration.CONF_FILE_DIR_ENV_NAME); - // Should not throw any exception when no external configuration file configured DFSPropertiesConfiguration.refreshGlobalProps(); - assertEquals(0, DFSPropertiesConfiguration.getGlobalProps().size()); + try { + if (!FSUtils.getFs(DFSPropertiesConfiguration.DEFAULT_PATH, new Configuration()).exists(DFSPropertiesConfiguration.DEFAULT_PATH)) { + assertEquals(0, DFSPropertiesConfiguration.getGlobalProps().size()); + } + } catch (IOException e) { + throw new HoodieIOException("Cannot check if the default config file exist: " + DFSPropertiesConfiguration.DEFAULT_PATH); + } } @Test