Skip to content

Commit

Permalink
[#4851] fix: make TestHiveTableOperations setup independently (#4857)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

`TestHiveTableOperations` can be tested before `TestHiveTable`
initialized.
Make `TestHiveTableOperations::steup()` run alone.

### Why are the changes needed?

When we try to just run `gradle :catalogs:catalog-hive:test --tests
'org.apache.gravitino.catalog.hive.TestHiveTableOperations'`,
`TestHiveTableOperations` needs static variables which must be
initialized ahead, and it can't be run alone.

Fix: #4851 

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Refactor of unit test setup, local unit tests have passed.

Co-authored-by: Edward Xu <[email protected]>
  • Loading branch information
github-actions[bot] and LindaSummer authored Sep 5, 2024
1 parent ba14a64 commit 25e13ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,25 @@ public class TestHiveTable extends MiniHiveMetastoreService {
private static void setup() {
hiveCatalog = initHiveCatalog();
hiveCatalogOperations = (HiveCatalogOperations) hiveCatalog.ops();
hiveSchema = initHiveSchema(hiveCatalog);
hiveSchema = initHiveSchema();
}

@AfterEach
private void resetSchema() {
hiveCatalogOperations.dropSchema(schemaIdent, true);
hiveSchema = initHiveSchema(hiveCatalog);
hiveSchema = initHiveSchema();
}

protected static HiveSchema initHiveSchema(HiveCatalog hiveCatalog) {
protected static HiveSchema initHiveSchema() {
return initHiveSchema(hiveCatalogOperations);
}

protected static HiveSchema initHiveSchema(HiveCatalogOperations ops) {
Map<String, String> properties = Maps.newHashMap();
properties.put("key1", "val1");
properties.put("key2", "val2");

return hiveCatalogOperations.createSchema(schemaIdent, HIVE_COMMENT, properties);
return ops.createSchema(schemaIdent, HIVE_COMMENT, properties);
}

protected static HiveCatalog initHiveCatalog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class TestHiveTableOperations extends MiniHiveMetastoreService {
public static void setup() {
hiveCatalog = initHiveCatalog();
hiveCatalogOperations = (HiveCatalogOperations) hiveCatalog.ops();
initHiveSchema(hiveCatalog);
initHiveSchema(hiveCatalogOperations);
hiveTable = createPartitionedTable();

// add partition: city=0/dt=2020-01-01
Expand Down

0 comments on commit 25e13ba

Please sign in to comment.