Skip to content
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

Adding PreUpdateRouting to BaseAspectRoutingResource #413

Merged
merged 13 commits into from
Sep 5, 2024
Prev Previous commit
Next Next commit
Added unit test
  • Loading branch information
Rakhi Agrawal committed Sep 4, 2024
commit 70925b589d85ecd8c60fd65b5c00c69830152fa7
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.linkedin.metadata.dao.BaseBrowseDAO;
import com.linkedin.metadata.dao.BaseLocalDAO;
import com.linkedin.metadata.dao.BaseSearchDAO;
import com.linkedin.metadata.dao.ingestion.SamplePreUpdateAspectRegistryImpl;
import com.linkedin.metadata.dao.utils.ModelUtils;
import com.linkedin.metadata.dao.utils.RecordUtils;
import com.linkedin.metadata.events.IngestionTrackingContext;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class BaseAspectRoutingResourceTest extends BaseEngineTest {
private BaseBrowseDAO _mockBrowseDAO;
private BaseLocalDAO _mockLocalDAO;
private BaseAspectRoutingGmsClient _mockAspectFooGmsClient;
private BaseAspectRoutingGmsClient _mockAspectBarGmsClient;
private BaseAspectRoutingGmsClient _mockAspectBazGmsClient;
private BaseAspectRoutingGmsClient _mockAspectAttributeGmsClient;

Expand Down Expand Up @@ -157,6 +159,7 @@ public ResourceContext getContext() {
@BeforeMethod
public void setup() {
_mockAspectFooGmsClient = mock(BaseAspectRoutingGmsClient.class);
_mockAspectBarGmsClient = mock(BaseAspectRoutingGmsClient.class);
_mockAspectAttributeGmsClient = mock(BaseAspectRoutingGmsClient.class);
_mockAspectBazGmsClient = mock(BaseAspectRoutingGmsClient.class);
when(_mockAspectFooGmsClient.getEntityType()).thenReturn(FooUrn.ENTITY_TYPE);
Expand Down Expand Up @@ -543,4 +546,31 @@ public void testBackfillWithNewValue() {
assertEquals(backfillResult.getEntities().size(), 2);
verifyZeroInteractions(_mockAspectFooGmsClient);
}

@Test
public void testPreUpdateRoutingWithRegisteredAspect() {
FooUrn urn = makeFooUrn(1);
AspectFoo foo = new AspectFoo().setValue("foo");
AspectFoo bar = new AspectFoo().setValue("bar");
List<EntityAspectUnion> aspects = Arrays.asList(ModelUtils.newAspectUnion(EntityAspectUnion.class, foo));
EntitySnapshot snapshot = ModelUtils.newSnapshot(EntitySnapshot.class, urn, aspects);
_resource.setRestliPreUpdateAspectRegistry(new SamplePreUpdateAspectRegistryImpl());
runAndWait(_resource.ingest(snapshot));
verify(_mockAspectFooGmsClient, times(1)).ingest(eq(urn), eq(bar));
verify(_mockLocalDAO, times(0)).add(eq(urn), eq(bar), any(), eq(null), eq(null));
verifyNoMoreInteractions(_mockLocalDAO);
}

@Test
public void testPreUpdateRoutingWithNonRegisteredPreUpdateAspect() {
FooUrn urn = makeFooUrn(1);
AspectBar bar = new AspectBar().setValue("bar");
List<EntityAspectUnion> aspects = Arrays.asList(ModelUtils.newAspectUnion(EntityAspectUnion.class, bar));
EntitySnapshot snapshot = ModelUtils.newSnapshot(EntitySnapshot.class, urn, aspects);
_resource.setRestliPreUpdateAspectRegistry(new SamplePreUpdateAspectRegistryImpl());
runAndWait(_resource.ingest(snapshot));
verify(_mockAspectBarGmsClient, times(0)).ingest(eq(urn), eq(bar));
verify(_mockLocalDAO, times(1)).add(eq(urn), eq(bar), any(), eq(null), eq(null));
verifyNoMoreInteractions(_mockLocalDAO);
}
}
Loading