Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jul 4, 2024
1 parent 6b4fa0b commit 697e605
Showing 1 changed file with 60 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ class MetacatSmokeSpec extends Specification {
/*
Step 4: create another table with the same name different uuid without specifying the parent child relation
but should fail because the table already exists
This test the revert should not impact the previous record
This test the revert during creation should not impact the previous record
*/
when:
child11TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, child11, 'amajumdar', child11Uri)
Expand Down Expand Up @@ -2151,36 +2151,7 @@ class MetacatSmokeSpec extends Specification {
assert e.message.contains("Cannot create a parent table on top of another parent")
/*
Step 7: create another table with the same parent1 name but should fail because the table already exists
Test the revert should not impact the previous record
*/
when:
api.createTable(catalogName, databaseName, parent1, parent1TableDto)
then:
e = thrown(Exception)
assert e.message.contains("already exists")
when:
parent1Table = api.getTable(catalogName, databaseName, parent1, true, true, false)
child11Table = api.getTable(catalogName, databaseName, child11, true, true, false)
then:
// Test Parent 1 parentChildInfo
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child11", "CLONE", "c11_uuid"),
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
// Test Child11 parentChildInfo
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
assert child11Table.definitionMetadata.get("random_key").asText() == "random_value"
JSONAssert.assertEquals(child11Table.definitionMetadata.get("parentChildRelationInfo").toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent1","relationType":"CLONE", "uuid":"p1_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child11).isEmpty()
/*
Step 8: Create one grandChild As a Parent of A child table should fail
Step 7: Create one grandChild As a Parent of A child table should fail
*/
when:
def grandchild121TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, grandChild121, 'amajumdar', null)
Expand All @@ -2192,7 +2163,7 @@ class MetacatSmokeSpec extends Specification {
assert e.message.contains("Cannot create a child table as parent")
/*
Step 9: Create another parent child that is disconnected with the above
Step 8: Create another parent child that is disconnected with the above
*/
when:
// Create Parent2
Expand Down Expand Up @@ -2220,7 +2191,8 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 10: Create a table newParent1 and attempt to rename parent1 to newParent1 should fail
Step 9: Create a table newParent1 without any parent child rel info
and attempt to rename parent1 to newParent1 should fail
Test the parentChildRelationship record remain the same after the revert
*/
when:
Expand Down Expand Up @@ -2257,6 +2229,53 @@ class MetacatSmokeSpec extends Specification {
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child12).isEmpty()
/*
Step 10: Attempt to rename parent1 to parent2 should fail
Test the parentChildRelationship record remain the same after the revert
*/
when:
api.renameTable(catalogName, databaseName, parent1, parent2)
then:
e = thrown(Exception)
assert e.message.contains("already exists in parent child relationship service")
when:
parent1Table = api.getTable(catalogName, databaseName, parent1, true, true, false)
child11Table = api.getTable(catalogName, databaseName, child11, true, true, false)
child12Table = api.getTable(catalogName, databaseName, child12, true, true, false)
parent2Table = api.getTable(catalogName, databaseName, parent2, true, true, false)
child21Table = api.getTable(catalogName, databaseName, child21, true, true, false)
then:
// Test Parent 1 parentChildInfo
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child11", "CLONE", "c11_uuid"),
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
// Test Child11 parentChildInfo
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
assert child11Table.definitionMetadata.get("random_key").asText() == "random_value"
JSONAssert.assertEquals(child11Table.definitionMetadata.get("parentChildRelationInfo").toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent1","relationType":"CLONE", "uuid":"p1_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child11).isEmpty()
// Test Child12 parentChildInfo
assert !child12Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child12Table.definitionMetadata.get("parentChildRelationInfo").toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent1","relationType":"CLONE","uuid":"p1_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child12).isEmpty()
// Test Parent 2 parentChildInfo
assert parent2Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent2) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child21", "CLONE", "c21_uuid")
] as Set
// Test Child21 parentChildInfo
JSONAssert.assertEquals(child21Table.definitionMetadata.get("parentChildRelationInfo").toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent2","relationType":"CLONE","uuid":"p2_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 11: First drop the newParent1 and then Rename parent1 to newParent1 should now succeed
Expand Down Expand Up @@ -2386,7 +2405,7 @@ class MetacatSmokeSpec extends Specification {
/*
Step 13: Drop previous renameChild11 and Rename child11 to renameChild11
Step 14: Drop previous renameChild11 and Rename child11 to renameChild11
*/
when:
api.deleteTable(catalogName, databaseName, renameChild11)
Expand Down Expand Up @@ -2417,7 +2436,7 @@ class MetacatSmokeSpec extends Specification {
assert e.message.contains("Unable to locate for")
/*
Step 14: Drop parent renameParent1
Step 15 Drop parent renameParent1
*/
when:
api.deleteTable(catalogName, databaseName, renameParent1)
Expand All @@ -2427,7 +2446,7 @@ class MetacatSmokeSpec extends Specification {
assert e.message.contains("because it still has")
/*
Step 15: Drop renameChild11 should succeed
Step 16: Drop renameChild11 should succeed
*/
when:
api.deleteTable(catalogName, databaseName, renameChild11)
Expand All @@ -2441,7 +2460,7 @@ class MetacatSmokeSpec extends Specification {
] as Set
/*
Step 16: Create renameChild11 and should expect random_key should appear at it is reattached
Step 17: Create renameChild11 and should expect random_key should appear at it is reattached
but parent childInfo should not as it is always coming from the parent child relationship service
which currently does not have any record
*/
Expand All @@ -2462,7 +2481,7 @@ class MetacatSmokeSpec extends Specification {
] as Set
/*
Step 17: Drop child12 should succeed
Step 18: Drop child12 should succeed
*/
when:
api.deleteTable(catalogName, databaseName, child12)
Expand All @@ -2472,7 +2491,7 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1).isEmpty()
/*
Step 18: Drop renameParent1 should succeed as there is no more child under it
Step 19: Drop renameParent1 should succeed as there is no more child under it
*/
when:
api.deleteTable(catalogName, databaseName, renameParent1)
Expand All @@ -2496,7 +2515,7 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 19: update parent2 with random parentChildRelationInfo to test immutability
Step 20: update parent2 with random parentChildRelationInfo to test immutability
*/
when:
def updateParent2Dto = parent2Table
Expand All @@ -2519,7 +2538,7 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 20: update child21 with random parentChildRelationInfo to test immutability
Step 21: update child21 with random parentChildRelationInfo to test immutability
*/
when:
def updateChild21Dto = child21Table
Expand Down

0 comments on commit 697e605

Please sign in to comment.