2323import  org .apache .hadoop .hive .metastore .HiveMetaHookLoader ;
2424import  org .apache .hadoop .hive .metastore .HiveMetaStoreClient ;
2525import  org .apache .hadoop .hive .metastore .IMetaStoreClient ;
26- import  org .apache .hadoop .hive .metastore .ServletSecurity ;
2726import  org .apache .hadoop .hive .metastore .api .Database ;
2827import  org .apache .hadoop .hive .metastore .api .FieldSchema ;
2928import  org .apache .hadoop .hive .metastore .api .MetaException ;
4645import  org .apache .iceberg .hive .CatalogUtils ;
4746import  org .apache .iceberg .hive .HiveSchemaUtil ;
4847import  org .apache .iceberg .rest .extension .HiveRESTCatalogServerExtension ;
49- import  org .junit .jupiter .api .AfterAll ;
48+ import  org .junit .jupiter .api .AfterEach ;
5049import  org .junit .jupiter .api .Assertions ;
51- import  org .junit .jupiter .api .BeforeAll ;
50+ import  org .junit .jupiter .api .BeforeEach ;
5251import  org .junit .jupiter .api .Test ;
53- import  org .junit .jupiter .api .TestInstance ;
54- import  org .junit .jupiter .api .extension .RegisterExtension ;
55- 
56- import  java .util .Collections ;
57- import  java .util .Map ;
5852
5953import  java .util .Arrays ;
54+ import  java .util .Collections ;
6055import  java .util .List ;
56+ import  java .util .Map ;
6157
6258import  static  org .junit .jupiter .api .Assertions .assertThrows ;
6359
6763  * The flow is as follows: 
6864  * Hive ql wrapper --> HiveMetaStoreClient --> HiveRESTCatalogClient --> HMS RESTCatalog Server --> HMS 
6965 */ 
70- @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
71- public  class  TestHiveRESTCatalogClientIT  {
72- 
73-   private  static  final  String  DB_NAME  = "ice_db" ;
74-   private  static  final  String  TABLE_NAME  = "ice_tbl" ;
75-   private  static  final  String  CATALOG_NAME  = "ice01" ;
76-   private  static  final  String  HIVE_ICEBERG_STORAGE_HANDLER  = "org.apache.iceberg.mr.hive.HiveIcebergStorageHandler" ;
66+ public  abstract  class  TestHiveRESTCatalogClientITBase  {
67+ 
68+   static  final  String  DB_NAME  = "ice_db" ;
69+   static  final  String  TABLE_NAME  = "ice_tbl" ;
70+   static  final  String  CATALOG_NAME  = "ice01" ;
71+   static  final  String  HIVE_ICEBERG_STORAGE_HANDLER  = "org.apache.iceberg.mr.hive.HiveIcebergStorageHandler" ;
72+   static  final  String  restCatalogPrefix  = String .format ("%s%s." , CatalogUtils .CATALOG_CONFIG_PREFIX , CATALOG_NAME );
73+ 
74+   HiveConf  hiveConf ;
75+   Configuration  conf ;
76+   Hive  hive ;
77+   IMetaStoreClient  msClient ;
7778
78-   private  Configuration  conf ;
79-   private  HiveConf  hiveConf ;
80-   private  Hive  hive ;
81- 
82-   private  IMetaStoreClient  msClient ;
79+   abstract  HiveRESTCatalogServerExtension  getHiveRESTCatalogServerExtension ();
8380
84-   @ RegisterExtension 
85-   private  static  final  HiveRESTCatalogServerExtension  REST_CATALOG_EXTENSION  =
86-       HiveRESTCatalogServerExtension .builder (ServletSecurity .AuthType .NONE )
87-           .addMetaStoreSchemaClassName (ITestsSchemaInfo .class )
88-           .build ();
81+   public  void  setupConf () {
82+     HiveRESTCatalogServerExtension  restCatalogExtension  = getHiveRESTCatalogServerExtension ();
8983
90-   @ BeforeAll 
91-   public  void  setup () throws  Exception  {
92-     // Starting msClient with Iceberg REST Catalog client underneath 
93-     String  restCatalogPrefix  = String .format ("%s%s." , CatalogUtils .CATALOG_CONFIG_PREFIX , CATALOG_NAME );
94- 
95-     conf  = REST_CATALOG_EXTENSION .getConf ();
84+     conf  = restCatalogExtension .getConf ();
9685
9786    MetastoreConf .setVar (conf , MetastoreConf .ConfVars .METASTORE_CLIENT_IMPL ,
9887        "org.apache.iceberg.hive.client.HiveRESTCatalogClient" );
9988    conf .set (MetastoreConf .ConfVars .CATALOG_DEFAULT .getVarname (), CATALOG_NAME );
100-     conf .set (restCatalogPrefix  + "uri" , REST_CATALOG_EXTENSION .getRestEndpoint ());
89+     conf .set (restCatalogPrefix  + "uri" , restCatalogExtension .getRestEndpoint ());
10190    conf .set (restCatalogPrefix  + "type" , CatalogUtil .ICEBERG_CATALOG_TYPE_REST );
91+   }
92+ 
93+   @ BeforeEach 
94+   void  setup () throws  Exception  {
95+     setupConf ();
10296
10397    HiveMetaHookLoader  hookLoader  = tbl  -> {
10498      HiveStorageHandler  storageHandler ;
@@ -109,18 +103,19 @@ public void setup() throws Exception {
109103      }
110104      return  storageHandler  == null  ? null  : storageHandler .getMetaHook ();
111105    };
112-      
106+ 
113107    msClient  = new  HiveMetaStoreClient (conf , hookLoader );
114108    hiveConf  = new  HiveConf (conf , HiveConf .class );
115109    hive  = Hive .get (hiveConf );
116110  }
117111
118-   @ AfterAll  public  void  tearDown () {
112+   @ AfterEach 
113+   public  void  tearDown () {
119114    if  (msClient  != null ) {
120115      msClient .close ();
121116    }
122117  }
123- 
118+    
124119  @ Test 
125120  public  void  testIceberg () throws  Exception  {
126121
@@ -142,7 +137,7 @@ public void testIceberg() throws Exception {
142137    // --- Get Databases --- 
143138    List <String > dbs  = msClient .getDatabases (CATALOG_NAME , "ice_*" );
144139    Assertions .assertEquals (1 , dbs .size ());
145-     Assertions .assertEquals (DB_NAME , dbs .get ( 0 ));
140+     Assertions .assertEquals (DB_NAME , dbs .getFirst ( ));
146141
147142    // --- Get All Databases --- 
148143    List <String > allDbs  = msClient .getAllDatabases (CATALOG_NAME );
@@ -151,7 +146,7 @@ public void testIceberg() throws Exception {
151146    Assertions .assertTrue (allDbs .contains (DB_NAME ));
152147
153148    // --- Create Table --- 
154-     org . apache . hadoop . hive . metastore . api . Table  tTable  = createPartitionedTable (msClient ,
149+     Table  tTable  = createPartitionedTable (msClient ,
155150        CATALOG_NAME , DB_NAME , TABLE_NAME , new  java .util .HashMap <>());
156151    Assertions .assertNotNull (tTable );
157152    Assertions .assertEquals (HiveMetaHook .ICEBERG , tTable .getParameters ().get (HiveMetaHook .TABLE_TYPE ));
@@ -166,7 +161,7 @@ public void testIceberg() throws Exception {
166161    Assertions .assertTrue (msClient .tableExists (CATALOG_NAME , DB_NAME , TABLE_NAME ));
167162
168163    // --- Get Table --- 
169-     org . apache . hadoop . hive . metastore . api . Table  table  = msClient .getTable (CATALOG_NAME , DB_NAME , TABLE_NAME );
164+     Table  table  = msClient .getTable (CATALOG_NAME , DB_NAME , TABLE_NAME );
170165    Assertions .assertEquals (DB_NAME , table .getDbName ());
171166    Assertions .assertEquals (TABLE_NAME , table .getTableName ());
172167    Assertions .assertEquals (HIVE_ICEBERG_STORAGE_HANDLER , table .getParameters ().get ("storage_handler" ));
0 commit comments