-
Notifications
You must be signed in to change notification settings - Fork 213
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
Add support for Destination Middleware #664
Conversation
@@ -235,6 +235,7 @@ public static String assertNotNullOrEmpty(String text, @Nullable String name) { | |||
/** Returns an immutable copy of the provided map. */ | |||
@NonNull | |||
public static <K, V> Map<K, V> immutableCopyOf(@NonNull Map<K, V> map) { | |||
// TODO (major version change) change this out to allow @Nullable input and guard against it |
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.
ideally this would become
@NonNull
public static <K, V> Map<K, V> immutableCopyOf(@Nullable Map<K, V> map) {
if (isNullOrEmpty(map)) {
return Collections.emptyMap();
}
return Collections.unmodifiableMap(new LinkedHashMap<>(map));
}
but dont wanna do a breaking change in this version.
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.
👍
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.
Might be good to leave that in the TODO comment in the code itself as well.
@@ -361,4 +366,44 @@ public void eventPlanOverridesSchemaDefault() throws IOException { | |||
+ "}")); | |||
verify(integration, never()).track(payload); | |||
} | |||
|
|||
@Test |
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.
These tests have nothing to do with destination middleware, but felt good to have as unit tests
* Add a {@link Middleware} custom source middleware. This will be run before sending to all | ||
* integrations | ||
*/ | ||
public Builder useSourceMiddleware(Middleware middleware) { |
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.
drop-in replacement for middleware
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.
perfect
* Add a {@link Middleware} custom source middleware. This will be run before sending to all | ||
* integrations | ||
*/ | ||
public Builder useSourceMiddleware(Middleware middleware) { |
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.
perfect
List<Middleware> applicableMiddleware = getMiddlewareList(destinationMiddleware, key); | ||
runMiddlewareChain( | ||
payload, | ||
applicableMiddleware, |
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.
the isIntegrationEnabled bit that seems to have been removed here seems like it might be important. If an integration is disabled on segment.com, there's no need to run it's middleware right?
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.
never mind, I see it down below. however, it's repeated. seems like that could be placed here instead and checked once?
@@ -235,6 +235,7 @@ public static String assertNotNullOrEmpty(String text, @Nullable String name) { | |||
/** Returns an immutable copy of the provided map. */ | |||
@NonNull | |||
public static <K, V> Map<K, V> immutableCopyOf(@NonNull Map<K, V> map) { | |||
// TODO (major version change) change this out to allow @Nullable input and guard against it |
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.
👍
@@ -235,6 +235,7 @@ public static String assertNotNullOrEmpty(String text, @Nullable String name) { | |||
/** Returns an immutable copy of the provided map. */ | |||
@NonNull | |||
public static <K, V> Map<K, V> immutableCopyOf(@NonNull Map<K, V> map) { | |||
// TODO (major version change) change this out to allow @Nullable input and guard against it |
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.
Might be good to leave that in the TODO comment in the code itself as well.
Summary
This PR implements destination specific middleware that function similar to source middleware, but instead run only for the specified integration.
These can be configured via the
Analytics.Builder
.Example
This PR also deprecates
middleware
forsourceMiddleware
which are middleware that run for all integrations.Ref: LIBMOBILE-38
Test Cases
DestinationMiddlewareTest.middlewareRuns
)DestinationMiddlewareTest.middlewareDoesNotRunForOtherIntegration
)DestinationMiddlewareTest.middlewareWillRunForMultipleIntegrations
)(
DestinationMiddlewareTest.middlewareCanShortCircuit
)(
DestinationMiddlewareTest.middlewareCanChain
)(
DestinationMiddlewareTest.middlewareCanTransform
)