Skip to content

Commit

Permalink
Fix path
Browse files Browse the repository at this point in the history
  • Loading branch information
Abacn committed Jan 27, 2025
1 parent 1f0ebd6 commit f4d47ba
Showing 1 changed file with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
Expand All @@ -43,10 +44,7 @@
import org.apache.hadoop.hive.metastore.IHMSHandler;
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.TSetIpAddressProcessor;
import org.apache.hadoop.hive.metastore.api.GetTableRequest;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.iceberg.ClientPool;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.common.DynConstructors;
import org.apache.iceberg.common.DynMethods;
import org.apache.iceberg.hadoop.Util;
Expand All @@ -63,8 +61,8 @@
* HiveMetastoreExtension} instead.
*
* <p>Copied over from <a
* href="https://github.com/apache/hive/blob/branch-4.0/iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java">Iceberg's
* integration testing util</a>
* href="https://github.com/apache/hive/blob/branch-4.0/iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/TestHiveMetastore.java">
* Hive metastore Iceberg integration utils</a>
*/
public class TestHiveMetastore {

Expand Down Expand Up @@ -114,7 +112,6 @@ public class TestHiveMetastore {
HIVE_LOCAL_DIR =
createTempDirectory("hive", asFileAttribute(fromString("rwxrwxrwx"))).toFile();
DERBY_PATH = new File(HIVE_LOCAL_DIR, "metastore_db").getPath();
HIVE_EXTERNAL_WAREHOUSE_DIR = new File(HIVE_LOCAL_DIR, "external");
File derbyLogFile = new File(HIVE_LOCAL_DIR, "derby.log");
System.setProperty("derby.stream.error.file", derbyLogFile.getAbsolutePath());
setupMetastoreDB("jdbc:derby:" + DERBY_PATH + ";create=true");
Expand Down Expand Up @@ -202,6 +199,12 @@ public void stop() throws Exception {
}
if (executorService != null) {
executorService.shutdown();
try {
// Give it a reasonable timeout
executorService.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
if (baseHandler != null) {
baseHandler.shutdown();
Expand Down Expand Up @@ -241,6 +244,9 @@ public void reset() throws Exception {

Path warehouseRoot = new Path(hiveWarehousePath);
FileSystem fs = Util.getFs(warehouseRoot, hiveConf);
if (!fs.exists(warehouseRoot)) {
return;
}
for (FileStatus fileStatus : fs.listStatus(warehouseRoot)) {
if (!fileStatus.getPath().getName().equals("derby.log")
&& !fileStatus.getPath().getName().equals("metastore_db")) {
Expand All @@ -249,14 +255,6 @@ public void reset() throws Exception {
}
}

public Table getTable(String dbName, String tableName) throws TException, InterruptedException {
return clientPool.run(client -> client.getTable(new GetTableRequest(dbName, tableName)));
}

public Table getTable(TableIdentifier identifier) throws TException, InterruptedException {
return getTable(identifier.namespace().toString(), identifier.name());
}

public <T> T run(ClientPool.Action<T, IMetaStoreClient, TException> action)
throws InterruptedException, TException {
return clientPool.run(action, false);
Expand Down Expand Up @@ -285,16 +283,13 @@ private TServer newThriftServer(TServerSocket socket, int poolSize, HiveConf con
private void initConf(HiveConf conf, int port) {
conf.set(HiveConf.ConfVars.METASTORE_URIS.varname, "thrift://localhost:" + port);
conf.set(HiveConf.ConfVars.METASTORE_WAREHOUSE.varname, hiveWarehousePath);
conf.set(
HiveConf.ConfVars.HIVE_METASTORE_WAREHOUSE_EXTERNAL.varname,
"file:" + HIVE_EXTERNAL_WAREHOUSE_DIR.getAbsolutePath());
conf.set(HiveConf.ConfVars.HIVE_METASTORE_WAREHOUSE_EXTERNAL.varname, hiveWarehousePath);
conf.set(HiveConf.ConfVars.METASTORE_TRY_DIRECT_SQL.varname, "false");
conf.set(HiveConf.ConfVars.METASTORE_DISALLOW_INCOMPATIBLE_COL_TYPE_CHANGES.varname, "false");
conf.set("iceberg.hive.client-pool-size", "2");
// set to false so that TxnManager#checkLock does not throw exception when using UNSET data type
// operation
// in the requested lock component
conf.setBoolVar(HiveConf.ConfVars.HIVE_IN_TEST, false);
// Setting this to avoid thrift exception during running Iceberg tests outside Iceberg.
conf.set(
HiveConf.ConfVars.HIVE_IN_TEST.varname, HiveConf.ConfVars.HIVE_IN_TEST.getDefaultValue());
}

private static void setupMetastoreDB(String dbURL) throws Exception {
Expand Down

0 comments on commit f4d47ba

Please sign in to comment.