-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gms): Fixes delete references for single relationship aspects #7211
Merged
pedro93
merged 6 commits into
datahub-project:master
from
acryldata:ps-fix-container-reference-delete
Feb 2, 2023
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b1e037c
fix(gms): Fixes delete references for single relationship aspects
pedro93 8d0024b
Apply review comments
pedro93 3f21e4d
Merge branch 'master' into ps-fix-container-reference-delete
pedro93 c6620d1
Merge branch 'master' into ps-fix-container-reference-delete
jjoyce0510 7dbe438
Merge branch 'master' into ps-fix-container-reference-delete
pedro93 8a151e2
Merge branch 'master' into ps-fix-container-reference-delete
pedro93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
metadata-io/src/test/java/com/linkedin/metadata/entity/DeleteEntityServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.linkedin.metadata.entity; | ||
|
||
import com.datahub.util.RecordUtils; | ||
import com.google.common.collect.ImmutableList; | ||
import com.linkedin.common.AuditStamp; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.container.Container; | ||
import com.linkedin.entity.EntityResponse; | ||
import com.linkedin.events.metadata.ChangeType; | ||
import com.linkedin.metadata.Constants; | ||
import com.linkedin.metadata.entity.ebean.EbeanAspectDao; | ||
import com.linkedin.metadata.event.EventProducer; | ||
import com.linkedin.metadata.graph.GraphService; | ||
import com.linkedin.metadata.graph.RelatedEntitiesResult; | ||
import com.linkedin.metadata.graph.RelatedEntity; | ||
import com.linkedin.metadata.models.registry.ConfigEntityRegistry; | ||
import com.linkedin.metadata.models.registry.EntityRegistry; | ||
import com.linkedin.metadata.query.filter.RelationshipDirection; | ||
import com.linkedin.metadata.run.DeleteReferencesResponse; | ||
import com.linkedin.metadata.snapshot.Snapshot; | ||
import com.linkedin.metadata.utils.AuditStampUtils; | ||
import com.linkedin.metadata.utils.SystemMetadataUtils; | ||
import java.sql.Timestamp; | ||
import java.util.Map; | ||
import org.mockito.Mockito; | ||
import org.testng.annotations.Test; | ||
|
||
import static com.linkedin.metadata.search.utils.QueryUtils.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.testng.AssertJUnit.*; | ||
|
||
|
||
public class DeleteEntityServiceTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scary if we did not have a class test for this previously :o |
||
|
||
protected EbeanAspectDao _aspectDao; | ||
|
||
protected EntityService _entityService; | ||
protected GraphService _graphService = Mockito.mock(GraphService.class); | ||
|
||
protected DeleteEntityService _deleteEntityService; | ||
|
||
protected EntityRegistry _entityRegistry; | ||
|
||
public DeleteEntityServiceTest() { | ||
_entityRegistry = new ConfigEntityRegistry(Snapshot.class.getClassLoader() | ||
.getResourceAsStream("entity-registry.yml")); | ||
_aspectDao = mock(EbeanAspectDao.class); | ||
_entityService = new EntityService(_aspectDao, mock(EventProducer.class), _entityRegistry); | ||
_deleteEntityService = new DeleteEntityService(_entityService, _graphService); | ||
} | ||
|
||
/** | ||
* This test checks whether deleting non array references in PDL aspects generates a valid MCP. | ||
*/ | ||
@Test | ||
public void testDeleteUniqueRefGeneratesValidMCP() { | ||
final Urn dataset = UrnUtils.toDatasetUrn("snowflake", "test", "DEV"); | ||
final Urn container = UrnUtils.getUrn("urn:li:container:d1006cf3-3ff9-48e3-85cd-26eb23775ab2"); | ||
|
||
final RelatedEntitiesResult mockRelatedEntities = | ||
new RelatedEntitiesResult(0, 1, 1, ImmutableList.of(new RelatedEntity("IsPartOf", dataset.toString()))); | ||
|
||
Mockito.when(_graphService.findRelatedEntities(null, newFilter("urn", container.toString()), | ||
null, EMPTY_FILTER, ImmutableList.of(), | ||
newRelationshipFilter(EMPTY_FILTER, RelationshipDirection.INCOMING), 0, 10000)) | ||
.thenReturn(mockRelatedEntities); | ||
|
||
final EntityResponse entityResponse = new EntityResponse(); | ||
entityResponse.setUrn(dataset); | ||
entityResponse.setEntityName(dataset.getEntityType()); | ||
final Container containerAspect = new Container(); | ||
containerAspect.setContainer(container); | ||
final EntityAspectIdentifier dbKey = new EntityAspectIdentifier(dataset.toString(), Constants.CONTAINER_ASPECT_NAME, 0); | ||
|
||
final EntityAspect dbValue = new EntityAspect(); | ||
dbValue.setUrn(dataset.toString()); | ||
dbValue.setVersion(0); | ||
dbValue.setAspect(Constants.CONTAINER_ASPECT_NAME); | ||
dbValue.setMetadata(RecordUtils.toJsonString(containerAspect)); | ||
dbValue.setSystemMetadata(RecordUtils.toJsonString(SystemMetadataUtils.createDefaultSystemMetadata())); | ||
final AuditStamp auditStamp = AuditStampUtils.createDefaultAuditStamp(); | ||
dbValue.setCreatedBy(auditStamp.getActor().toString()); | ||
dbValue.setCreatedOn(new Timestamp(auditStamp.getTime())); | ||
|
||
final Map<EntityAspectIdentifier, EntityAspect> dbEntries = Map.of(dbKey, dbValue); | ||
Mockito.when(_aspectDao.batchGet(Mockito.any())).thenReturn(dbEntries); | ||
|
||
RollbackResult result = new RollbackResult(container, Constants.DATASET_ENTITY_NAME, | ||
Constants.CONTAINER_ASPECT_NAME, containerAspect, null, null, null, | ||
ChangeType.DELETE, false, 1); | ||
|
||
Mockito.when(_aspectDao.runInTransactionWithRetry(Mockito.any(), Mockito.anyInt())) | ||
.thenReturn(result); | ||
|
||
final DeleteReferencesResponse response = _deleteEntityService.deleteReferencesTo(container, false); | ||
assertEquals(1, (int) response.getTotal()); | ||
assertFalse(response.getRelatedAspects().isEmpty()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing!