Skip to content

Commit

Permalink
Hive: Make HiveMetastoreExtension configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra committed Dec 13, 2023
1 parent 36ecab4 commit 341605d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.nio.file.Path;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.apache.iceberg.AppendFiles;
import org.apache.iceberg.CatalogProperties;
Expand Down Expand Up @@ -68,7 +67,7 @@ public class HiveCreateReplaceTableTest {

@RegisterExtension
private static final HiveMetastoreExtension HIVE_METASTORE_EXTENSION =
new HiveMetastoreExtension(DB_NAME, Collections.emptyMap());
HiveMetastoreExtension.builder().withDatabase(DB_NAME).build();

private static HiveCatalog catalog;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HiveMetastoreExtension implements BeforeAllCallback, AfterAllCallba
private final Map<String, String> hiveConfOverride;
private final String databaseName;

public HiveMetastoreExtension(String databaseName, Map<String, String> hiveConfOverride) {
private HiveMetastoreExtension(String databaseName, Map<String, String> hiveConfOverride) {
this.databaseName = databaseName;
this.hiveConfOverride = hiveConfOverride;
}
Expand All @@ -50,9 +50,11 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception {

metastore.start(hiveConfWithOverrides);
metastoreClient = new HiveMetaStoreClient(hiveConfWithOverrides);
String dbPath = metastore.getDatabasePath(databaseName);
Database db = new Database(databaseName, "description", dbPath, Maps.newHashMap());
metastoreClient.createDatabase(db);
if (null != databaseName) {
String dbPath = metastore.getDatabasePath(databaseName);
Database db = new Database(databaseName, "description", dbPath, Maps.newHashMap());
metastoreClient.createDatabase(db);
}
}

@Override
Expand Down Expand Up @@ -80,4 +82,29 @@ public HiveConf hiveConf() {
public TestHiveMetastore metastore() {
return metastore;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private String databaseName;
private Map<String, String> config;

public Builder() {}

public Builder withDatabase(String databaseToCreate) {
this.databaseName = databaseToCreate;
return this;
}

public Builder withConfig(Map<String, String> configToSet) {
this.config = configToSet;
return this;
}

public HiveMetastoreExtension build() {
return new HiveMetastoreExtension(databaseName, config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.File;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand All @@ -52,7 +51,7 @@ public class HiveTableBaseTest {

@RegisterExtension
protected static final HiveMetastoreExtension HIVE_METASTORE_EXTENSION =
new HiveMetastoreExtension(DB_NAME, Collections.emptyMap());
HiveMetastoreExtension.builder().withDatabase(DB_NAME).build();

protected static HiveCatalog catalog;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -44,7 +43,7 @@ public class TestCachedClientPool {

@RegisterExtension
private static final HiveMetastoreExtension HIVE_METASTORE_EXTENSION =
new HiveMetastoreExtension(DB_NAME, Collections.emptyMap());
HiveMetastoreExtension.builder().withDatabase(DB_NAME).build();

@Test
public void testClientPoolCleaner() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -105,7 +104,7 @@ public class TestHiveCatalog {

@RegisterExtension
private static final HiveMetastoreExtension HIVE_METASTORE_EXTENSION =
new HiveMetastoreExtension(DB_NAME, Collections.emptyMap());
HiveMetastoreExtension.builder().withDatabase(DB_NAME).build();

@BeforeEach
public void before() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ public class TestHiveCommitLocks {

@RegisterExtension
private static final HiveMetastoreExtension HIVE_METASTORE_EXTENSION =
new HiveMetastoreExtension(
DB_NAME, ImmutableMap.of(HiveConf.ConfVars.HIVE_TXN_TIMEOUT.varname, "1s"));
HiveMetastoreExtension.builder()
.withDatabase(DB_NAME)
.withConfig(ImmutableMap.of(HiveConf.ConfVars.HIVE_TXN_TIMEOUT.varname, "1s"))
.build();

private static HiveCatalog catalog;
private Path tableLocation;
Expand Down

0 comments on commit 341605d

Please sign in to comment.