difin commented on code in PR #6327:
URL: https://github.com/apache/hive/pull/6327#discussion_r2914488222
##########
itests/qtest-iceberg/src/test/java/org/apache/hadoop/hive/cli/TestStandaloneRESTCatalogServer.java:
##########
@@ -17,211 +17,171 @@
*/
package org.apache.hadoop.hive.cli;
-import java.io.File;
+import java.io.IOException;
+
import org.apache.hadoop.conf.Configuration;
import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
-import org.apache.hadoop.hive.metastore.MetaStoreTestUtils;
-import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+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 (no
auth).
+ *
* 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
*/
-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());
- }
-
- @After
- public void teardown() {
- if (restCatalogServer != null) {
- restCatalogServer.stop();
+@RunWith(SpringRunner.class)
+@SpringBootTest(
+ classes =
BaseStandaloneRESTCatalogServerTest.TestRestCatalogApplication.class,
+ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
+ properties = {
+
"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration"
}
- if (hmsPort > 0) {
- MetaStoreTestUtils.close(hmsPort);
- }
- if (hmsTempDir != null && hmsTempDir.exists()) {
- deleteDirectory(hmsTempDir);
+)
+@ContextConfiguration(initializers =
TestStandaloneRESTCatalogServer.RestCatalogTestContextInitializer.class)
+@TestExecutionListeners(
+ listeners = BaseStandaloneRESTCatalogServerTest.HmsStartupListener.class,
+ mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
+)
+public class TestStandaloneRESTCatalogServer extends
BaseStandaloneRESTCatalogServerTest {
+ @LocalServerPort
+ private int port;
+
+ @Autowired
+ private StandaloneRESTCatalogServer server;
+
+ @Override
+ protected int getPort() {
+ return port;
+ }
+
+ /**
+ * Registers Configuration and StandaloneRESTCatalogServer before the
context loads.
+ * Mirrors production main() - we create both and register them, so Spring
uses our
+ * Configuration (with THRIFT_URIS from HMS) and never tries to instantiate
the server.
+ */
+ public static class RestCatalogTestContextInitializer
+ implements ApplicationContextInitializer<ConfigurableApplicationContext>
{
+ @Override
+ public void initialize(ConfigurableApplicationContext context) {
+ 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");
+ MetastoreConf.setLongVar(restCatalogConf, ConfVars.CATALOG_SERVLET_PORT,
0);
+ context.getBeanFactory().registerSingleton("hadoopConfiguration",
restCatalogConf);
+ StandaloneRESTCatalogServer server = new
StandaloneRESTCatalogServer(restCatalogConf);
+
context.getBeanFactory().registerSingleton("standaloneRESTCatalogServer",
server);
}
}
-
+
+ @AfterClass
+ public static void teardownClass() throws IOException {
+ teardownBase();
+ }
+
+ @Override
@Test(timeout = 60000)
- public void testHealthCheck() throws Exception {
- LOG.info("=== Test: Health Check ===");
-
- String healthUrl = "http://localhost:" + restCatalogServer.getPort() +
"/health";
- try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
- HttpGet request = new HttpGet(healthUrl);
- try (CloseableHttpResponse response = httpClient.execute(request)) {
- assertEquals("Health check should return 200", 200,
response.getStatusLine().getStatusCode());
- LOG.info("Health check passed");
- }
- }
+ public void testLivenessProbe() throws Exception {
+ LOG.info("=== Test: Liveness Probe (Kubernetes) ===");
+ super.testLivenessProbe();
}
-
+
+ @Override
+ @Test(timeout = 60000)
+ public void testReadinessProbe() throws Exception {
+ LOG.info("=== Test: Readiness Probe (Kubernetes) ===");
+ super.testReadinessProbe();
+ }
+
+ @Override
+ @Test(timeout = 60000)
+ public void testPrometheusMetrics() throws Exception {
+ LOG.info("=== Test: Prometheus Metrics (for K8s HPA) ===");
+ super.testPrometheusMetrics();
+ }
+
@Test(timeout = 60000)
public void testRESTCatalogConfig() throws Exception {
LOG.info("=== Test: REST Catalog Config Endpoint ===");
-
- String configUrl = restCatalogServer.getRestEndpoint() + "/v1/config";
- try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
- HttpGet request = new HttpGet(configUrl);
- try (CloseableHttpResponse response = httpClient.execute(request)) {
- assertEquals("Config endpoint should return 200", 200,
response.getStatusLine().getStatusCode());
-
- String responseBody = EntityUtils.toString(response.getEntity());
- LOG.info("Config response: {}", responseBody);
- // ConfigResponse should contain endpoints, defaults, and overrides
- assertTrue("Response should contain endpoints",
responseBody.contains("endpoints"));
- assertTrue("Response should be valid JSON",
responseBody.startsWith("{") && responseBody.endsWith("}"));
- }
+
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response =
httpClient.execute(get("/iceberg/v1/config"))) {
+ assertEquals("Config endpoint should return 200", 200,
response.getStatusLine().getStatusCode());
+
+ String responseBody = EntityUtils.toString(response.getEntity());
+ LOG.info("Config response: {}", responseBody);
+ assertTrue("Response should contain endpoints",
responseBody.contains("endpoints"));
+ assertTrue("Response should be valid JSON", responseBody.startsWith("{")
&& responseBody.endsWith("}"));
}
}
-
+
@Test(timeout = 60000)
public void testRESTCatalogNamespaceOperations() throws Exception {
LOG.info("=== Test: REST Catalog Namespace Operations ===");
-
- String namespacesUrl = restCatalogServer.getRestEndpoint() +
"/v1/namespaces";
+
+ String namespacePath = "/iceberg/v1/namespaces";
Review Comment:
Done
--
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]