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


##########
itests/qtest-iceberg/src/test/java/org/apache/hadoop/hive/cli/TestIcebergRESTCatalogGravitinoLlapLocalCliDriver.java:
##########
@@ -0,0 +1,301 @@
+/*
+ * 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 com.github.dockerjava.api.command.CopyArchiveFromContainerCmd;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.cli.control.CliAdapter;
+import org.apache.hadoop.hive.cli.control.CliConfigs;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.hive.CatalogUtils;
+import org.apache.iceberg.hive.client.HiveRESTCatalogClient;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.MountableFile;
+import org.testcontainers.containers.GenericContainer;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+@RunWith(Parameterized.class)
+public class TestIcebergRESTCatalogGravitinoLlapLocalCliDriver {
+
+  private static final CliAdapter CLI_ADAPTER =
+      new 
CliConfigs.TestIcebergRESTCatalogGravitinoLlapLocalCliDriver().getCliAdapter();
+  
+  private static final Logger LOG = 
LoggerFactory.getLogger(TestIcebergRESTCatalogGravitinoLlapLocalCliDriver.class);
+  
+  private static final String CATALOG_NAME = "ice01";
+  private static final long GRAVITINO_STARTUP_TIMEOUT_MINUTES = 5L;
+  private static final String GRAVITINO_CONF_FILE_TEMPLATE = 
"gravitino-h2-test-template.conf";
+  private static final String GRAVITINO_ROOT_DIR = 
"/root/gravitino-iceberg-rest-server";
+  private static final String GRAVITINO_STARTUP_SCRIPT = GRAVITINO_ROOT_DIR + 
"/bin/start-iceberg-rest-server.sh";
+  private static final String GRAVITINO_H2_LIB = GRAVITINO_ROOT_DIR + 
"/libs/h2-driver.jar";
+  private static final String GRAVITINO_CONF_FILE = GRAVITINO_ROOT_DIR + 
"/conf/gravitino-iceberg-rest-server.conf";
+  private static final DockerImageName GRAVITINO_IMAGE =
+      DockerImageName.parse("apache/gravitino-iceberg-rest:1.0.0");
+
+  private final String name;
+  private final File qfile;
+
+  private GenericContainer<?> gravitinoContainer;
+  private Path warehouseDir;
+  private final ScheduledExecutorService fileSyncExecutor = 
Executors.newSingleThreadScheduledExecutor();
+
+  @Parameters(name = "{0}")
+  public static List<Object[]> getParameters() throws Exception {
+    return CLI_ADAPTER.getParameters();
+  }
+
+  @ClassRule
+  public static final TestRule CLI_CLASS_RULE = CLI_ADAPTER.buildClassRule();
+
+  @Rule
+  public final TestRule cliTestRule = CLI_ADAPTER.buildTestRule();
+
+  public TestIcebergRESTCatalogGravitinoLlapLocalCliDriver(String name, File 
qfile) {
+    this.name = name;
+    this.qfile = qfile;
+  }
+
+  @Before
+  public void setup() throws IOException {
+    createWarehouseDir();
+    prepareGravitinoConfig();
+    startGravitinoContainer();
+    startWarehouseDirSync();
+
+    String host = gravitinoContainer.getHost();
+    Integer port = gravitinoContainer.getMappedPort(9001);
+    String restCatalogPrefix = String.format("%s%s.", 
CatalogUtils.CATALOG_CONFIG_PREFIX, CATALOG_NAME);
+
+    // Suppress IntelliJ warning about using HTTP since this is a local test 
container connection
+    @SuppressWarnings("HttpUrlsUsage")
+    String restCatalogUri = String.format("http://%s:%d/iceberg";, host, port);
+
+    Configuration conf = SessionState.get().getConf();
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.METASTORE_CLIENT_IMPL, 
HiveRESTCatalogClient.class.getName());
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, 
CATALOG_NAME);
+    conf.set(restCatalogPrefix + "uri", restCatalogUri);
+    conf.set(restCatalogPrefix + "type", 
CatalogUtil.ICEBERG_CATALOG_TYPE_REST);
+  }
+
+  @After
+  public void teardown() {
+    if (gravitinoContainer != null) {
+      gravitinoContainer.stop();
+    }
+
+    fileSyncExecutor.shutdownNow();
+
+    if (warehouseDir != null && Files.exists(warehouseDir)) {
+      try (var paths = Files.walk(warehouseDir)) {
+        paths.sorted(Comparator.reverseOrder())

Review Comment:
   can we use FileUtils.cleanDirectory(warehouseDir) ?



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