-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included Entity type in the routing map (#455)
* Fixed routing map * Addressed comments --------- Co-authored-by: Rakhi Agrawal <[email protected]>
- Loading branch information
Showing
8 changed files
with
195 additions
and
25 deletions.
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
49 changes: 49 additions & 0 deletions
49
dao-api/src/main/java/com/linkedin/metadata/dao/ingestion/AspectCallbackMapKey.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,49 @@ | ||
package com.linkedin.metadata.dao.ingestion; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import lombok.Data; | ||
|
||
|
||
/** | ||
* A key class used in the AspectCallbackRegistry map to uniquely identify aspect callback routing clients. | ||
* The key is a combination of the aspect class and the entity type. | ||
*/ | ||
@Data | ||
public class AspectCallbackMapKey { | ||
private final Class<? extends RecordTemplate> aspectClass; | ||
private final String entityType; | ||
|
||
/** | ||
* Indicates whether some other object is "equal to" this one. | ||
* Two AspectCallbackMapKey objects are considered equal if their aspectClass and entityType are equal. | ||
* | ||
* @param o the reference object with which to compare | ||
* @return true if this object is the same as the obj argument; false otherwise | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AspectCallbackMapKey that = (AspectCallbackMapKey) o; | ||
return aspectClass.equals(that.aspectClass) && entityType.equals(that.entityType); | ||
} | ||
|
||
/** | ||
* Returns a hash code value for the object. | ||
* The hash code is computed based on the aspectClass and entityType. | ||
* | ||
* @return a hash code value for this object | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
int result = aspectClass.hashCode(); | ||
result = 31 * result + entityType.hashCode(); | ||
return result; | ||
} | ||
} | ||
|
||
|
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
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
68 changes: 68 additions & 0 deletions
68
dao-api/src/test/java/com/linkedin/metadata/dao/ingestion/AspectCallbackMapKeyTest.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,68 @@ | ||
package com.linkedin.metadata.dao.ingestion; | ||
|
||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.testing.AspectBar; | ||
import com.linkedin.testing.AspectFoo; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
import static org.testng.Assert.*; | ||
|
||
|
||
public class AspectCallbackMapKeyTest { | ||
|
||
@Test | ||
public void testConstructorAndGetters() { | ||
// Use a real class instead of mocking | ||
Class<? extends RecordTemplate> mockAspectClass = RecordTemplate.class; | ||
String entityType = "testEntity"; | ||
|
||
// Create an instance of AspectCallbackMapKey | ||
AspectCallbackMapKey key = new AspectCallbackMapKey(mockAspectClass, entityType); | ||
|
||
// Verify that the getters return the correct values | ||
assertEquals(mockAspectClass, key.getAspectClass()); | ||
assertEquals(entityType, key.getEntityType()); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
// Create mock instances of RecordTemplate class | ||
Class<? extends RecordTemplate> mockAspectClass1 = AspectFoo.class; | ||
Class<? extends RecordTemplate> mockAspectClass2 = AspectBar.class; | ||
String entityType1 = "testEntity1"; | ||
String entityType2 = "testEntity2"; | ||
|
||
// Create instances of AspectCallbackMapKey | ||
AspectCallbackMapKey key1 = new AspectCallbackMapKey(mockAspectClass1, entityType1); | ||
AspectCallbackMapKey key2 = new AspectCallbackMapKey(mockAspectClass1, entityType1); | ||
AspectCallbackMapKey key3 = new AspectCallbackMapKey(mockAspectClass2, entityType1); | ||
AspectCallbackMapKey key4 = new AspectCallbackMapKey(mockAspectClass1, entityType2); | ||
|
||
// Verify equality | ||
assertEquals(key1, key2); // Same class and entity type | ||
assertNotEquals(key1, key3); // Different class, same entity type | ||
assertNotEquals(key1, key4); // Same class, different entity type | ||
assertNotEquals(key1, null); // Not equal to null | ||
assertNotEquals(key1, new Object()); // Not equal to a different type | ||
} | ||
|
||
@Test | ||
public void testHashCode() { | ||
// Create mock instances of RecordTemplate class | ||
Class<? extends RecordTemplate> mockAspectClass1 = AspectFoo.class; | ||
Class<? extends RecordTemplate> mockAspectClass2 = AspectBar.class; | ||
String entityType1 = "testEntity1"; | ||
String entityType2 = "testEntity2"; | ||
|
||
// Create instances of AspectCallbackMapKey | ||
AspectCallbackMapKey key1 = new AspectCallbackMapKey(mockAspectClass1, entityType1); | ||
AspectCallbackMapKey key2 = new AspectCallbackMapKey(mockAspectClass1, entityType1); | ||
AspectCallbackMapKey key3 = new AspectCallbackMapKey(mockAspectClass2, entityType1); | ||
AspectCallbackMapKey key4 = new AspectCallbackMapKey(mockAspectClass1, entityType2); | ||
|
||
assertEquals(key1.hashCode(), key2.hashCode()); | ||
assertNotEquals(key1.hashCode(), key3.hashCode()); | ||
assertNotEquals(key1.hashCode(), key4.hashCode()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
dao-api/src/test/java/com/linkedin/metadata/dao/ingestion/AspectCallbackRegistryTest.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,48 @@ | ||
package com.linkedin.metadata.dao.ingestion; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import com.linkedin.testing.AspectBar; | ||
import com.linkedin.testing.AspectFoo; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
|
||
public class AspectCallbackRegistryTest { | ||
private AspectCallbackRegistry registry; | ||
private AspectCallbackRoutingClient client1; | ||
private AspectCallbackRoutingClient client2; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
client1 = new SampleAspectCallbackRoutingClient(); | ||
client2 = new SampleAspectCallbackRoutingClient(); | ||
|
||
Map<AspectCallbackMapKey, AspectCallbackRoutingClient> aspectCallbackMap = new HashMap<>(); | ||
aspectCallbackMap.put(new AspectCallbackMapKey(AspectFoo.class, "entityType1"), client1); | ||
aspectCallbackMap.put(new AspectCallbackMapKey(AspectBar.class, "entityType2"), client2); | ||
|
||
registry = new AspectCallbackRegistry(aspectCallbackMap); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
assertNotNull(registry); | ||
} | ||
|
||
@Test | ||
public void testGetAspectCallbackRoutingClient() { | ||
assertEquals(registry.getAspectCallbackRoutingClient(AspectFoo.class, "entityType1"), client1); | ||
assertEquals(registry.getAspectCallbackRoutingClient(AspectBar.class, "entityType2"), client2); | ||
assertNull(registry.getAspectCallbackRoutingClient(AspectFoo.class, "entityType2")); | ||
} | ||
|
||
@Test | ||
public void testIsRegistered() { | ||
assertTrue(registry.isRegistered(AspectFoo.class, "entityType1")); | ||
assertTrue(registry.isRegistered(AspectBar.class, "entityType2")); | ||
assertFalse(registry.isRegistered(AspectFoo.class, "entityType2")); | ||
} | ||
} |
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
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