Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jul 1, 2024
1 parent 399354c commit 562d852
Showing 1 changed file with 69 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.netflix.metacat

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.metacat.client.Client
import com.netflix.metacat.client.api.MetacatV1
Expand Down Expand Up @@ -2034,6 +2033,7 @@ class MetacatSmokeSpec extends Specification {
// Create child11 Table with parent = parent1
def child11TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, child11, 'amajumdar', child11Uri)
initializeParentChildRelDefinitionMetadata(child11TableDto, parent1FullName, parent1UUID, child11UUID)
child11TableDto.definitionMetadata.put("random_key", "random_value")
api.createTable(catalogName, databaseName, child11, child11TableDto)
def parent1Table = api.getTable(catalogName, databaseName, parent1, true, true, false)
Expand All @@ -2046,13 +2046,26 @@ class MetacatSmokeSpec extends Specification {
// Test Child11 parentChildInfo
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
assert child11Table.definitionMetadata.get("random_key").asText() == "random_value"
JSONAssert.assertEquals(child11ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent1","relationType":"CLONE", "uuid":"p1_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child11).isEmpty()
/*
Step 2: Create a second child (child12) pointing to parent = parent1
Step 2: create another table with the same name different uuid on the same parent should fail
*/
when:
child11TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, child11, 'amajumdar', child11Uri)
initializeParentChildRelDefinitionMetadata(child11TableDto, parent1FullName, parent1UUID, "random_uuid")
api.createTable(catalogName, databaseName, child11, child11TableDto)
then:
def e = thrown(Exception)
assert e.message.contains("Cannot have a child table having more than one parent")
/*
Step 3: Create a second child (child12) pointing to parent = parent1
*/
when:
// Create Child2 Table
Expand All @@ -2079,7 +2092,20 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child12).isEmpty()
/*
Step 3: Create one grandChild As a Parent of A child table should fail
Step 4: create a parent table on top of another parent table should fail
*/
when:
def grandParent1 = "grandparent1"
def grandParent1UUID = "grandparent2_uuid"
def parent1TableDtoCopy = PigDataDtoProvider.getTable(catalogName, databaseName, parent1, 'amajumdar', parent1Uri)
initializeParentChildRelDefinitionMetadata(parent1TableDtoCopy, grandParent1, grandParent1UUID, parent1UUID)
api.createTable(catalogName, databaseName, parent1, parent1TableDtoCopy)
then:
e = thrown(Exception)
assert e.message.contains("Cannot create a parent table on top of another parent")
/*
Step 5: Create one grandChild As a Parent of A child table should fail
*/
when:
def grandchild121TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, grandChild121, 'amajumdar', null)
Expand All @@ -2089,10 +2115,11 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, grandChild121).isEmpty()
then:
thrown(Exception)
e = thrown(Exception)
assert e.message.contains("Cannot create a child table as parent")
/*
Step 4: Create another parent child that is disconnected with the above
Step 6: Create another parent child that is disconnected with the above
*/
when:
// Create Parent2
Expand Down Expand Up @@ -2121,7 +2148,7 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 5: Rename parent1 to newParent1
Step 7: Rename parent1 to newParent1
*/
when:
api.renameTable(catalogName, databaseName, parent1, renameParent1)
Expand Down Expand Up @@ -2153,8 +2180,15 @@ class MetacatSmokeSpec extends Specification {
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child12).isEmpty()
//get the parent oldName should fail as it no longer exists
when:
api.getTable(catalogName, databaseName, parent1)
then:
e = thrown(Exception)
assert e.message.contains("because it still has child table")
/*
Step 6: Rename child11 to renameChild11
Step 8: Rename child11 to renameChild11
*/
when:
api.renameTable(catalogName, databaseName, child11, renameChild11)
Expand All @@ -2169,20 +2203,21 @@ class MetacatSmokeSpec extends Specification {
] as Set
// Test Child11 parentChildInfo with newName
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
assert child11Table.definitionMetadata.get("random_key").asText() == "random_value"
JSONAssert.assertEquals(child11ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/rename_parent1","relationType":"CLONE","uuid":"p1_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, renameChild11).isEmpty()
/*
Step 7: Drop parent renameParent1
Step 9: Drop parent renameParent1
*/
when:
api.deleteTable(catalogName, databaseName, renameParent1)
then:
def e = thrown(Exception)
e.message.contains("because it still has child table")
e = thrown(Exception)
assert e.message.contains("because it still has child table")
/*
Step 8: Drop renameChild11
Expand All @@ -2197,8 +2232,26 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
/*
Step 10: Create renameChild11 and should expect parent childInfo is not present
but random_key should be reattached
*/
when:
api.createTable(catalogName, databaseName, renameChild11, child11TableDto)
then:
assert !child11Table.definitionMetadata.has("parentChildRelationInfo")
assert child11Table.definitionMetadata.get("random_key").asText() == "random_value"
assert parentChildRelV1.getChildren(catalogName, databaseName, child11).isEmpty()
// Test parent1 Table still only have child12
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
/*
Step 9: Drop child12
Step 11: Drop child12
*/
when:
api.deleteTable(catalogName, databaseName, child12)
Expand All @@ -2208,7 +2261,7 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1).isEmpty()
/*
Step 10: Drop renameParent1
Step 12: Drop renameParent1
*/
when:
api.deleteTable(catalogName, databaseName, renameParent1)
Expand All @@ -2233,12 +2286,11 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 11: update parent2 with random parentChildRelationInfo
Step 13: update parent2 with random parentChildRelationInfo
*/
when:
def updateParent2Dto = parent2Table
updateParent2Dto.definitionMetadata.put("parent", "CLONE")
updateParent2Dto.definitionMetadata.put("childInfos", "CLONE")
initializeParentChildRelDefinitionMetadata(updateParent2Dto, "RANDOM", "RANDOM", "RANDOM")
api.updateTable(catalogName, databaseName, parent2, updateParent2Dto)
parent2Table = api.getTable(catalogName, databaseName, parent2, true, true, false)
Expand All @@ -2258,12 +2310,11 @@ class MetacatSmokeSpec extends Specification {
assert parentChildRelV1.getChildren(catalogName, databaseName, child21).isEmpty()
/*
Step 12: update child21 with random parentChildRelationInfo
Step 14: update child21 with random parentChildRelationInfo
*/
when:
def updateChild21Dto = child21Table
updateChild21Dto.definitionMetadata.put("parent", "CLONE")
updateChild21Dto.definitionMetadata.put("childInfos", "CLONE")
initializeParentChildRelDefinitionMetadata(updateParent2Dto, "RANDOM", "RANDOM", "RANDOM")
api.updateTable(catalogName, databaseName, child21, updateChild21Dto)
parent2Table = api.getTable(catalogName, databaseName, parent2, true, true, false)
Expand Down

0 comments on commit 562d852

Please sign in to comment.