-
Notifications
You must be signed in to change notification settings - Fork 32
(feat): Feature Management Activate and GetVariation Listener #272
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
Conversation
added unit tests for getVariation listener and activate listeners
Pull Request Test Coverage Report for Build 902
💛 - Coveralls |
Pull Request Test Coverage Report for Build 961
💛 - Coveralls |
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.
Looks good for most part. Name changes needed.
package com.optimizely.ab.notification; | ||
|
||
public class DecisionInfoEnums { | ||
public enum ActivateVariationDecisionInfo { |
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.
This should be called ExperimentDecisionInfo
.
@@ -33,13 +33,32 @@ | |||
* more flexible. | |||
*/ | |||
public class NotificationCenter { | |||
public enum OnDecisionNotificationType { | |||
IS_FEATURE_ENABLED("feature"), |
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.
This should be DecisionNotificationType
and suggest changing:
IS_FEATURE_ENABLED --> FEATURE
GET_FEATURE_VARIABLE --> FEATURE_VARIABLE
* @param type - The notification type. | ||
* @param userId - The userId passed into activate. | ||
* @param attributes - The filtered attribute list passed into activate | ||
* @param decisionInfo - The decision Information containing all parameters passed in api. |
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.
nit information and API.
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.
Minor feedback. Please take a look.
* onDecision called when an activate was triggered | ||
* | ||
* @param type - The notification type. | ||
* @param userId - The userId passed into activate. |
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.
nit. userId
passed to the API.
* | ||
* @param type - The notification type. | ||
* @param userId - The userId passed into activate. | ||
* @param attributes - The filtered attribute list passed into activate |
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.
nit. attribute map passed to the API
@@ -110,7 +150,7 @@ public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @ | |||
*/ | |||
public int addTrackNotificationListener(final TrackNotificationListenerInterface trackNotificationListenerInterface) { | |||
if (trackNotificationListenerInterface instanceof TrackNotificationListener) { | |||
return addNotificationListener(NotificationType.Activate, (NotificationListener) trackNotificationListenerInterface); | |||
return addNotificationListener(NotificationType.Track, (NotificationListener) trackNotificationListenerInterface); |
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.
Oh. We will have to fix this in a patch version in the meanwhile I think.
Thoughts @thomaszurkan-optimizely ?
@@ -42,6 +42,8 @@ | |||
import com.optimizely.ab.notification.ActivateNotificationListener; | |||
import com.optimizely.ab.notification.NotificationCenter; | |||
import com.optimizely.ab.notification.TrackNotificationListener; | |||
import com.optimizely.ab.notification.DecisionNotificationListener; |
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.
nit. Please alphabetize.
// activate the experiment | ||
Variation actualVariation = optimizely.activate(activatedExperiment.getKey(), userId, null); | ||
|
||
// verify that the bucketing algorithm was called correctly |
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.
This comment seems irrelevant / incorrect.
|
||
assertNull(actualVariation); | ||
|
||
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId)); |
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.
Shouldn't we check that notification listener was called?
|
||
verify(mockEventHandler, times(1)).dispatchEvent(any(LogEvent.class)); | ||
|
||
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId)); |
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.
Shouldn't we check notification listener was called?
Variation actualVariation = optimizely.getVariation(experiment.getKey(), userId, testUserAttributes); | ||
|
||
verify(mockBucketer).bucket(experiment, bucketingId); | ||
|
||
assertThat(actualVariation, is(bucketedVariation)); | ||
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId)); |
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.
Where is the check for listener being called?
@@ -2636,6 +2638,153 @@ public void getVariationWithInvalidDatafile() throws Exception { | |||
|
|||
//======== Notification listeners ========// | |||
|
|||
Boolean isListenerCalled = false; |
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.
Similar comment in #271 as to how to properly assert something like this.
Variation variation = decisionService.getVariation(experiment, userId, copiedAttributes); | ||
|
||
Map<String, Object> decisionInfo = new HashMap<>(); | ||
decisionInfo.put(DecisionInfoEnums.ExperimentDecisionInfo.EXPERIMENT_KEY.toString(), experiment.getKey()); |
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.
Similar comment in #270 on how to make this cleaner.
return this; | ||
} | ||
|
||
public ExperimentDecisionNotificationBuilder withVariation(Variation variation) { |
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.
I feel this should be withVariationKey
. Just seems inconsistent.
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.
Actually I am passing variation here so that on build we can verify null check before getting key from its object
if (decisionNotificationListener != null) { | ||
for (NotificationHolder holder : decisionListenerHolder) { | ||
if (holder.decisionNotificationListener == decisionNotificationListener) { | ||
// TODO: 3/27/2019 change log level from warn to info and to return existing listener ID |
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.
Is this relevant still?
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.
yes we need to fix it in separate PR as Mike davis suggested
Summary
##Ticket:
OASIS-4228