-
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.
Adding PreUpdateRouting to BaseAspectRoutingResource (#413)
* Adding PreUpdateRouting to BaseAspect * Added a comment * Update BaseAspectRoutingResource.java * Added unit test * Fixed return type * Added protobuf * Fixed java doc * Fixed compilation error * Addressed comments * Checkstyle error * Forgot to change at other place * Using fqcn * Updated unit tests --------- Co-authored-by: Rakhi Agrawal <[email protected]>
- Loading branch information
Showing
5 changed files
with
173 additions
and
1 deletion.
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
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
30 changes: 30 additions & 0 deletions
30
...c/test/java/com/linkedin/metadata/restli/ingestion/SamplePreUpdateAspectRegistryImpl.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,30 @@ | ||
package com.linkedin.metadata.restli.ingestion; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.metadata.dao.ingestion.RestliCompliantPreUpdateRoutingClient; | ||
import com.linkedin.metadata.dao.ingestion.RestliPreUpdateAspectRegistry; | ||
import com.linkedin.testing.AspectFoo; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
|
||
public class SamplePreUpdateAspectRegistryImpl implements RestliPreUpdateAspectRegistry { | ||
private final ImmutableMap<Class<? extends RecordTemplate>, RestliCompliantPreUpdateRoutingClient> registry; | ||
|
||
public SamplePreUpdateAspectRegistryImpl() { | ||
registry = new ImmutableMap.Builder<Class<? extends RecordTemplate>, RestliCompliantPreUpdateRoutingClient>() | ||
.put(AspectFoo.class, new SamplePreUpdateRoutingClient()) | ||
.build(); | ||
} | ||
@Nullable | ||
@Override | ||
public <ASPECT extends RecordTemplate> RestliCompliantPreUpdateRoutingClient getPreUpdateRoutingClient(@Nonnull ASPECT aspect) { | ||
return registry.get(aspect.getClass()); | ||
} | ||
|
||
@Override | ||
public <ASPECT extends RecordTemplate> boolean isRegistered(@Nonnull Class<ASPECT> aspectClass) { | ||
return registry.containsKey(aspectClass); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...es/src/test/java/com/linkedin/metadata/restli/ingestion/SamplePreUpdateRoutingClient.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,41 @@ | ||
package com.linkedin.metadata.restli.ingestion; | ||
|
||
import com.google.protobuf.Any; | ||
import com.google.protobuf.Message; | ||
import com.google.protobuf.StringValue; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.metadata.dao.ingestion.RestliCompliantPreUpdateRoutingClient; | ||
import com.linkedin.testing.AspectFoo; | ||
|
||
|
||
public class SamplePreUpdateRoutingClient implements RestliCompliantPreUpdateRoutingClient { | ||
@Override | ||
public Message routingLambda(Message urn, Message aspect) { | ||
// For testing, change the aspect value to "bar" | ||
return Any.pack(StringValue.of("bar")); | ||
} | ||
|
||
@Override | ||
public Message convertUrnToMessage(Urn urn) { | ||
// Directly wrap the URN string into a Protobuf message for testing | ||
return Any.pack(StringValue.of(urn.toString())); | ||
} | ||
|
||
@Override | ||
public Message convertAspectToMessage(RecordTemplate pegasusAspect) { | ||
// For testing, convert AspectFoo to a TestMessageProtos.AspectMessage | ||
// Assuming the aspect has a `value` field and its string representation can be used for now | ||
String aspectString = pegasusAspect.toString(); // Extracting the aspect as a string (e.g., {value=foo}) | ||
|
||
// Wrap the aspect string into a simple Protobuf message for testing | ||
return Any.pack(StringValue.of(aspectString)); | ||
} | ||
|
||
@Override | ||
public RecordTemplate convertAspectFromMessage(Message messageAspect) { | ||
// For testing, convert TestMessageProtos.AspectMessage back to AspectFoo | ||
// Create a new RecordTemplate (AspectFoo in this case) and set the value field | ||
return new AspectFoo().setValue("bar"); | ||
} | ||
} |