deniskuzZ commented on code in PR #6327:
URL: https://github.com/apache/hive/pull/6327#discussion_r2833504607


##########
itests/qtest-iceberg/src/test/java/org/apache/hadoop/hive/cli/TestStandaloneRESTCatalogServer.java:
##########
@@ -31,114 +31,199 @@
 import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
 import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
 import org.apache.iceberg.rest.standalone.StandaloneRESTCatalogServer;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.TestContext;
+import org.springframework.test.context.TestExecutionListener;
+import org.springframework.test.context.TestExecutionListeners;
+import org.springframework.test.context.junit4.SpringRunner;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 /**
- * Integration test for Standalone REST Catalog Server.
- * 
+ * Integration test for Standalone REST Catalog Server with Spring Boot.
+ *
  * Tests that the standalone server can:
- * 1. Start independently of HMS
+ * 1. Start independently of HMS using Spring Boot
  * 2. Connect to an external HMS instance
  * 3. Serve REST Catalog requests
- * 4. Provide health check endpoint
+ * 4. Provide health check endpoints (liveness and readiness)
+ * 5. Expose Prometheus metrics
  */
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+    classes = {StandaloneRESTCatalogServer.class, 
TestStandaloneRESTCatalogServer.TestConfig.class},
+    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
+    properties = {
+        "spring.main.allow-bean-definition-overriding=true",
+        
"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration"
+    }
+)
+@TestExecutionListeners(
+    listeners = TestStandaloneRESTCatalogServer.HmsStartupListener.class,
+    mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
+)
 public class TestStandaloneRESTCatalogServer {
   private static final Logger LOG = 
LoggerFactory.getLogger(TestStandaloneRESTCatalogServer.class);
-  
-  private Configuration hmsConf;
-  private Configuration restCatalogConf;
-  private int hmsPort;
-  private StandaloneRESTCatalogServer restCatalogServer;
-  private File warehouseDir;
-  private File hmsTempDir;
-  
-  @Before
-  public void setup() throws Exception {
-    // Setup temporary directories
-    hmsTempDir = new File(System.getProperty("java.io.tmpdir"), "test-hms-" + 
System.currentTimeMillis());
-    hmsTempDir.mkdirs();
-    warehouseDir = new File(hmsTempDir, "warehouse");
-    warehouseDir.mkdirs();
-    
-    // Configure and start embedded HMS
-    hmsConf = MetastoreConf.newMetastoreConf();
-    MetaStoreTestUtils.setConfForStandloneMode(hmsConf);
-    
-    String jdbcUrl = String.format("jdbc:derby:memory:%s;create=true",
-        new File(hmsTempDir, "metastore_db").getAbsolutePath());
-    MetastoreConf.setVar(hmsConf, ConfVars.CONNECT_URL_KEY, jdbcUrl);
-    MetastoreConf.setVar(hmsConf, ConfVars.WAREHOUSE, 
warehouseDir.getAbsolutePath());
-    MetastoreConf.setVar(hmsConf, ConfVars.WAREHOUSE_EXTERNAL, 
warehouseDir.getAbsolutePath());
-    
-    // Start HMS
-    hmsPort = MetaStoreTestUtils.startMetaStoreWithRetry(
-        HadoopThriftAuthBridge.getBridge(), hmsConf, true, false, false, 
false);
-    LOG.info("Started embedded HMS on port: {}", hmsPort);
-    
-    // Configure standalone REST Catalog server
-    restCatalogConf = MetastoreConf.newMetastoreConf();
-    String hmsUri = "thrift://localhost:" + hmsPort;
-    MetastoreConf.setVar(restCatalogConf, ConfVars.THRIFT_URIS, hmsUri);
-    MetastoreConf.setVar(restCatalogConf, ConfVars.WAREHOUSE, 
warehouseDir.getAbsolutePath());
-    MetastoreConf.setVar(restCatalogConf, ConfVars.WAREHOUSE_EXTERNAL, 
warehouseDir.getAbsolutePath());
-    
-    // Configure REST Catalog servlet
-    int restPort = MetaStoreTestUtils.findFreePort();
-    MetastoreConf.setLongVar(restCatalogConf, ConfVars.CATALOG_SERVLET_PORT, 
restPort);
-    MetastoreConf.setVar(restCatalogConf, 
ConfVars.ICEBERG_CATALOG_SERVLET_PATH, "iceberg");
-    MetastoreConf.setVar(restCatalogConf, ConfVars.CATALOG_SERVLET_AUTH, 
"none");
-    
-    // Start standalone REST Catalog server
-    restCatalogServer = new StandaloneRESTCatalogServer(restCatalogConf);
-    restCatalogServer.start();
-    LOG.info("Started standalone REST Catalog server on port: {}", 
restCatalogServer.getPort());
+
+  @LocalServerPort
+  private int port;
+
+  @Autowired
+  private StandaloneRESTCatalogServer server;
+
+  private static Configuration hmsConf;
+  private static int hmsPort;
+  private static File warehouseDir;
+  private static File hmsTempDir;
+
+  /**
+   * Starts HMS before the Spring ApplicationContext loads.
+   * Spring loads the context before @BeforeClass, so we use a 
TestExecutionListener
+   * which runs before context initialization.
+   */
+  public static class HmsStartupListener implements TestExecutionListener {
+    @Override
+    public void beforeTestClass(TestContext testContext) throws Exception {
+      if (hmsPort > 0) {
+        return; // Already started
+      }
+      hmsTempDir = new File(System.getProperty("java.io.tmpdir"), "test-hms-" 
+ System.currentTimeMillis());
+      hmsTempDir.mkdirs();
+      warehouseDir = new File(hmsTempDir, "warehouse");
+      warehouseDir.mkdirs();
+
+      hmsConf = MetastoreConf.newMetastoreConf();
+      MetaStoreTestUtils.setConfForStandloneMode(hmsConf);
+
+      String jdbcUrl = String.format("jdbc:derby:memory:%s;create=true",
+          new File(hmsTempDir, "metastore_db").getAbsolutePath());
+      MetastoreConf.setVar(hmsConf, ConfVars.CONNECT_URL_KEY, jdbcUrl);
+      MetastoreConf.setVar(hmsConf, ConfVars.WAREHOUSE, 
warehouseDir.getAbsolutePath());
+      MetastoreConf.setVar(hmsConf, ConfVars.WAREHOUSE_EXTERNAL, 
warehouseDir.getAbsolutePath());
+
+      hmsPort = MetaStoreTestUtils.startMetaStoreWithRetry(
+          HadoopThriftAuthBridge.getBridge(), hmsConf, true, false, false, 
false);
+      LOG.info("Started embedded HMS on port: {} (before Spring context)", 
hmsPort);
+    }
   }
-  
-  @After
-  public void teardown() {
-    if (restCatalogServer != null) {
-      restCatalogServer.stop();
+
+  /**
+   * Test configuration that provides the Configuration bean.
+   * Spring injects this into StandaloneRESTCatalogServer constructor.
+   */
+  @TestConfiguration
+  public static class TestConfig {
+    @Bean
+    public Configuration hadoopConfiguration() {
+      // Create Configuration for REST Catalog (standard Hive approach)
+      Configuration restCatalogConf = MetastoreConf.newMetastoreConf();
+      String hmsUri = "thrift://localhost:" + hmsPort;
+      MetastoreConf.setVar(restCatalogConf, ConfVars.THRIFT_URIS, hmsUri);
+      MetastoreConf.setVar(restCatalogConf, ConfVars.WAREHOUSE, 
warehouseDir.getAbsolutePath());
+      MetastoreConf.setVar(restCatalogConf, ConfVars.WAREHOUSE_EXTERNAL, 
warehouseDir.getAbsolutePath());
+      MetastoreConf.setVar(restCatalogConf, 
ConfVars.ICEBERG_CATALOG_SERVLET_PATH, "iceberg");
+      MetastoreConf.setVar(restCatalogConf, ConfVars.CATALOG_SERVLET_AUTH, 
"none");
+      // HMSCatalogFactory returns null when CATALOG_SERVLET_PORT is -1; use 0 
for Spring Boot managed port
+      MetastoreConf.setLongVar(restCatalogConf, ConfVars.CATALOG_SERVLET_PORT, 
0);
+      return restCatalogConf;
     }
+  }
+
+  @AfterClass
+  public static void teardownClass() {
     if (hmsPort > 0) {
       MetaStoreTestUtils.close(hmsPort);
     }
     if (hmsTempDir != null && hmsTempDir.exists()) {
-      deleteDirectory(hmsTempDir);
+      deleteDirectoryStatic(hmsTempDir);
+    }
+  }
+
+  private static void deleteDirectoryStatic(File directory) {
+    if (directory.exists()) {

Review Comment:
   don't we have utils to do the recursive delete 
`FileUtils.deleteDirectory(directory)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to