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


##########
itests/qtest-iceberg/src/test/java/org/apache/hadoop/hive/cli/BaseStandaloneRESTCatalogServerTest.java:
##########
@@ -0,0 +1,358 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.cli;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.FileUtils;
+import org.apache.http.HttpHeaders;
+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.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLContexts;
+import org.apache.http.conn.ssl.TrustStrategy;
+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 javax.servlet.http.HttpServlet;
+
+import org.apache.iceberg.rest.standalone.IcebergCatalogConfiguration;
+import org.apache.iceberg.rest.standalone.RestCatalogServerRuntime;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.Import;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.test.context.TestContext;
+import org.springframework.test.context.TestExecutionListener;
+import org.springframework.web.util.UriComponentsBuilder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Base class for Standalone REST Catalog Server integration tests.
+ *
+ * Provides shared setup (HMS, listeners), HTTP helpers (with optional auth), 
and common tests
+ * (liveness, readiness, Prometheus, server port). Subclasses provide 
auth-specific configuration
+ * and tests.
+ */
+public abstract class BaseStandaloneRESTCatalogServerTest {
+  protected static final Logger LOG = 
LoggerFactory.getLogger(BaseStandaloneRESTCatalogServerTest.class);
+
+  protected static Configuration hmsConf;
+  protected static int hmsPort;
+  protected static File warehouseDir;
+  protected static File hmsTempDir;
+
+  @LocalServerPort
+  private int port;
+
+  @Autowired
+  private RestCatalogServerRuntime server;
+
+  /**
+   * Starts HMS before the Spring ApplicationContext loads.
+   * Spring loads the context before @BeforeClass, so we use a 
TestExecutionListener
+   * which runs before context initialization.
+   */
+  @Order(Ordered.HIGHEST_PRECEDENCE)
+  public static class HmsStartupListener implements TestExecutionListener {
+    private static final String TEMP_DIR_PREFIX = 
"StandaloneRESTCatalogServer";
+
+    @Override
+    public void beforeTestClass(TestContext testContext) throws Exception {
+      if (hmsPort > 0) {
+        return;
+      }
+      String uniqueTestKey = String.format("%s_%s", TEMP_DIR_PREFIX, 
UUID.randomUUID());
+      hmsTempDir = new 
File(MetaStoreTestUtils.getTestWarehouseDir(uniqueTestKey));
+      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);
+    }
+  }
+
+  @SpringBootApplication
+  @Import(TestCatalogConfig.class)
+  @ComponentScan(
+      basePackages = "org.apache.iceberg.rest.standalone",
+      excludeFilters = {
+          @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = 
IcebergCatalogConfiguration.class),
+          @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = 
RestCatalogServerRuntime.class)
+      })
+  public static class TestRestCatalogApplication {}
+
+  /**
+   * Test-specific config providing the REST catalog servlet.
+   * Uses Configuration from test's TestConfig (with hmsPort, warehouseDir).
+   * Does NOT import IcebergCatalogConfiguration to avoid production 
hadoopConfiguration.
+   */
+  @org.springframework.context.annotation.Configuration
+  static class TestCatalogConfig {
+
+    @Bean
+    public Configuration hadoopConfiguration() {
+      Configuration conf = createBaseTestConfiguration();
+      MetastoreConf.setVar(conf, ConfVars.CATALOG_SERVLET_AUTH, "none");
+      return conf;
+    }
+
+    @Bean
+    public RestCatalogServerRuntime restCatalogServerRuntime(ServerProperties 
serverProperties) {
+      Configuration conf = createBaseTestConfiguration();
+      MetastoreConf.setVar(conf, ConfVars.CATALOG_SERVLET_AUTH, "none");
+      return new RestCatalogServerRuntime(conf, serverProperties);
+    }
+
+    @Bean
+    public ServletRegistrationBean<HttpServlet> 
restCatalogServlet(Configuration conf) {
+      return IcebergCatalogConfiguration.createRestCatalogServlet(conf);

Review Comment:
   can we move the whole thing here instead of static constructor?



-- 
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