1818
1919package org .apache .hudi .table .catalog ;
2020
21+ import org .apache .flink .table .catalog .exceptions .CatalogException ;
2122import org .apache .hadoop .hive .conf .HiveConf ;
22- import org .junit .jupiter .api .io .TempDir ;
2323
24- import java .io .File ;
25-
26- import static org .apache .hudi .table .catalog .HoodieCatalogFactoryOptions .HIVE_SITE_FILE ;
24+ import java .io .IOException ;
2725
2826/** Test utils for Hoodie catalog. */
2927public class TestHoodieCatalogUtils {
@@ -32,8 +30,7 @@ public class TestHoodieCatalogUtils {
3230
3331 private static final String TEST_CATALOG_NAME = "test-catalog" ;
3432
35- @ TempDir
36- static File tempFile ;
33+ private static final org .junit .rules .TemporaryFolder TEMPORARY_FOLDER = new org .junit .rules .TemporaryFolder ();
3734
3835 /** Create a HiveCatalog with an embedded Hive Metastore. */
3936 public static HoodieHiveCatalog createHiveCatalog () {
@@ -50,18 +47,20 @@ public static HoodieHiveCatalog createHiveCatalog(String name) {
5047
5148 public static HiveConf createHiveConf () {
5249 ClassLoader classLoader = TestHoodieCatalogUtils .class .getClassLoader ();
50+ try {
51+ TEMPORARY_FOLDER .create ();
52+ String warehouseDir = TEMPORARY_FOLDER .newFolder ().getAbsolutePath () + "/metastore_db" ;
53+ String warehouseUri = String .format (HIVE_WAREHOUSE_URI_FORMAT , warehouseDir );
5354
54- new File (tempFile ,"db" ).mkdir ();
55- File metastore_db = new File (tempFile ,"/db/metastore_db" );
56- String warehouseUri = String .format (HIVE_WAREHOUSE_URI_FORMAT , metastore_db .getAbsolutePath ());
57-
58- HiveConf .setHiveSiteLocation (classLoader .getResource (HIVE_SITE_FILE ));
59-
60- File hive_warehouse = new File (tempFile ,"/hive_warehouse" );
61- hive_warehouse .mkdir () ;
62- HiveConf hiveConf = new HiveConf ();
63- hiveConf .setVar (HiveConf .ConfVars .METASTOREWAREHOUSE , hive_warehouse .getAbsolutePath ());
64- hiveConf .setVar (HiveConf .ConfVars .METASTORECONNECTURLKEY , warehouseUri );
65- return hiveConf ;
55+ HiveConf .setHiveSiteLocation (classLoader .getResource (HoodieCatalogFactoryOptions .HIVE_SITE_FILE ));
56+ HiveConf hiveConf = new HiveConf ();
57+ hiveConf .setVar (
58+ HiveConf .ConfVars .METASTOREWAREHOUSE ,
59+ TEMPORARY_FOLDER .newFolder ("hive_warehouse" ).getAbsolutePath ());
60+ hiveConf .setVar (HiveConf .ConfVars .METASTORECONNECTURLKEY , warehouseUri );
61+ return hiveConf ;
62+ } catch (IOException e ) {
63+ throw new CatalogException ("Failed to create test HiveConf to HiveCatalog." , e );
64+ }
6665 }
6766}
0 commit comments