Skip to content

Commit 47c65b5

Browse files
update: add Javadoc comments for async decision methods and config creation in CMAB client
1 parent 3cee65c commit 47c65b5

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

core-api/src/main/java/com/optimizely/ab/OptimizelyUserContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,19 @@ public void decideForKeysAsync(@Nonnull List<String> keys,
313313

314314
/**
315315
* Returns decision results asynchronously for multiple flag keys.
316+
*
317+
* @param keys A list of flag keys for which decisions will be made.
318+
* @param callback A callback to invoke when decisions are available.
316319
*/
317320
public void decideForKeysAsync(@Nonnull List<String> keys, @Nonnull OptimizelyDecisionsCallback callback) {
318321
decideForKeysAsync(keys, callback, Collections.emptyList());
319322
}
320323

321324
/**
322325
* Returns decision results asynchronously for all active flag keys.
326+
*
327+
* @param callback A callback to invoke when decisions are available.
328+
* @param options A list of options for decision-making.
323329
*/
324330
public void decideAllAsync(@Nonnull OptimizelyDecisionsCallback callback,
325331
@Nonnull List<OptimizelyDecideOption> options) {
@@ -329,6 +335,8 @@ public void decideAllAsync(@Nonnull OptimizelyDecisionsCallback callback,
329335

330336
/**
331337
* Returns decision results asynchronously for all active flag keys.
338+
*
339+
* @param callback A callback to invoke when decisions are available.
332340
*/
333341
public void decideAllAsync(@Nonnull OptimizelyDecisionsCallback callback) {
334342
decideAllAsync(callback, Collections.emptyList());

core-api/src/main/java/com/optimizely/ab/bucketing/DecisionService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public DecisionService(@Nonnull Bucketer bucketer,
106106
* @param options An array of decision options
107107
* @param userProfileTracker tracker for reading and updating user profile of the user
108108
* @param reasons Decision reasons
109+
* @param useCmab Boolean flag to determine if cmab service is to be used
109110
* @return A {@link DecisionResponse} including the {@link Variation} that user is bucketed into (or null) and the decision reasons
110111
*/
111112
@Nonnull

core-api/src/main/java/com/optimizely/ab/cmab/client/CmabClientConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ public RetryConfig getRetryConfig() {
3535

3636
/**
3737
* Creates a config with default retry settings.
38+
*
39+
* @return A default cmab client config
3840
*/
3941
public static CmabClientConfig withDefaultRetry() {
4042
return new CmabClientConfig(RetryConfig.defaultConfig());
4143
}
4244

4345
/**
4446
* Creates a config with no retry.
47+
*
48+
* @return A cmab client config with no retry
4549
*/
4650
public static CmabClientConfig withNoRetry() {
4751
return new CmabClientConfig(null);

core-api/src/main/java/com/optimizely/ab/cmab/client/RetryConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ public RetryConfig(int maxRetries) {
6262

6363
/**
6464
* Creates a default RetryConfig with 3 retries and exponential backoff.
65+
*
66+
* @return Retry config with default settings
6567
*/
6668
public static RetryConfig defaultConfig() {
6769
return new RetryConfig(3);
6870
}
6971

7072
/**
7173
* Creates a RetryConfig with no retries (single attempt only).
74+
*
75+
* @return Retry config with no retries
7276
*/
7377
public static RetryConfig noRetry() {
7478
return new RetryConfig(0, 0, 1.0, 0);

core-api/src/test/java/com/optimizely/ab/bucketing/DecisionServiceTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ public void getVariationsForFeatureListBatchesUpsLoadAndSave() throws Exception
566566
ErrorHandler mockErrorHandler = mock(ErrorHandler.class);
567567
UserProfileService mockUserProfileService = mock(UserProfileService.class);
568568

569-
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, mockUserProfileService, null);
569+
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, mockUserProfileService, mockCmabService);
570570

571571
FeatureFlag featureFlag1 = FEATURE_FLAG_MULTI_VARIATE_FEATURE;
572572
FeatureFlag featureFlag2 = FEATURE_FLAG_MULTI_VARIATE_FUTURE_FEATURE;
@@ -626,7 +626,7 @@ public void getVariationForFeatureInRolloutReturnsNullWhenUserIsExcludedFromAllT
626626
mockBucketer,
627627
mockErrorHandler,
628628
null,
629-
null
629+
mockCmabService
630630
);
631631

632632
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(
@@ -653,7 +653,7 @@ public void getVariationForFeatureInRolloutReturnsNullWhenUserFailsAllAudiencesA
653653
Bucketer mockBucketer = mock(Bucketer.class);
654654
when(mockBucketer.bucket(any(Experiment.class), anyString(), any(ProjectConfig.class))).thenReturn(DecisionResponse.nullNoReasons());
655655

656-
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, null);
656+
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, mockCmabService);
657657

658658
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(
659659
FEATURE_FLAG_MULTI_VARIATE_FEATURE,
@@ -684,7 +684,7 @@ public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsAllAudie
684684
mockBucketer,
685685
mockErrorHandler,
686686
null,
687-
null
687+
mockCmabService
688688
);
689689

690690
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(
@@ -726,7 +726,7 @@ public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficI
726726
mockBucketer,
727727
mockErrorHandler,
728728
null,
729-
null
729+
mockCmabService
730730
);
731731

732732
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(
@@ -767,7 +767,7 @@ public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficI
767767
mockBucketer,
768768
mockErrorHandler,
769769
null,
770-
null
770+
mockCmabService
771771
);
772772

773773
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(
@@ -806,7 +806,7 @@ public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTargetin
806806
when(mockBucketer.bucket(eq(everyoneElseRule), anyString(), any(ProjectConfig.class))).thenReturn(DecisionResponse.responseNoReasons(everyoneElseVariation));
807807
when(mockBucketer.bucket(eq(englishCitizensRule), anyString(), any(ProjectConfig.class))).thenReturn(DecisionResponse.responseNoReasons(englishCitizenVariation));
808808

809-
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, null);
809+
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, mockCmabService);
810810

811811
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(
812812
FEATURE_FLAG_MULTI_VARIATE_FEATURE,
@@ -959,7 +959,7 @@ public void bucketReturnsVariationStoredInUserProfile() throws Exception {
959959
when(userProfileService.lookup(userProfileId)).thenReturn(userProfile.toMap());
960960

961961
Bucketer bucketer = new Bucketer();
962-
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, null);
962+
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, mockCmabService);
963963

964964
logbackVerifier.expectMessage(Level.INFO,
965965
"Returning previously activated variation \"" + variation.getKey() + "\" of experiment \"" + experiment.getKey() + "\""
@@ -985,7 +985,7 @@ public void getStoredVariationLogsWhenLookupReturnsNull() throws Exception {
985985
UserProfile userProfile = new UserProfile(userProfileId, Collections.<String, Decision>emptyMap());
986986
when(userProfileService.lookup(userProfileId)).thenReturn(userProfile.toMap());
987987

988-
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, null);
988+
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, mockCmabService);
989989

990990
logbackVerifier.expectMessage(Level.INFO, "No previously activated variation of experiment " +
991991
"\"" + experiment.getKey() + "\" for user \"" + userProfileId + "\" found in user profile.");
@@ -1012,7 +1012,7 @@ public void getStoredVariationReturnsNullWhenVariationIsNoLongerInConfig() throw
10121012
UserProfileService userProfileService = mock(UserProfileService.class);
10131013
when(userProfileService.lookup(userProfileId)).thenReturn(storedUserProfile.toMap());
10141014

1015-
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, null);
1015+
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, mockCmabService);
10161016

10171017
logbackVerifier.expectMessage(Level.INFO,
10181018
"User \"" + userProfileId + "\" was previously bucketed into variation with ID \"" + storedVariationId + "\" for " +
@@ -1043,7 +1043,7 @@ public void getVariationSavesBucketedVariationIntoUserProfile() throws Exception
10431043
Bucketer mockBucketer = mock(Bucketer.class);
10441044
when(mockBucketer.bucket(eq(experiment), eq(userProfileId), eq(noAudienceProjectConfig))).thenReturn(DecisionResponse.responseNoReasons(variation));
10451045

1046-
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, userProfileService, null);
1046+
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, userProfileService, mockCmabService);
10471047

10481048
assertEquals(variation, decisionService.getVariation(
10491049
experiment, optimizely.createUserContext(userProfileId, Collections.emptyMap()), noAudienceProjectConfig).getResult()
@@ -1105,7 +1105,7 @@ public void getVariationSavesANewUserProfile() throws Exception {
11051105

11061106
Bucketer bucketer = mock(Bucketer.class);
11071107
UserProfileService userProfileService = mock(UserProfileService.class);
1108-
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, null);
1108+
DecisionService decisionService = new DecisionService(bucketer, mockErrorHandler, userProfileService, mockCmabService);
11091109

11101110
when(bucketer.bucket(eq(experiment), eq(userProfileId), eq(noAudienceProjectConfig))).thenReturn(DecisionResponse.responseNoReasons(variation));
11111111
when(userProfileService.lookup(userProfileId)).thenReturn(null);
@@ -1117,7 +1117,7 @@ public void getVariationSavesANewUserProfile() throws Exception {
11171117
@Test
11181118
public void getVariationBucketingId() throws Exception {
11191119
Bucketer bucketer = mock(Bucketer.class);
1120-
DecisionService decisionService = spy(new DecisionService(bucketer, mockErrorHandler, null, null));
1120+
DecisionService decisionService = spy(new DecisionService(bucketer, mockErrorHandler, null, mockCmabService));
11211121
Experiment experiment = validProjectConfig.getExperiments().get(0);
11221122
Variation expectedVariation = experiment.getVariations().get(0);
11231123

@@ -1152,7 +1152,7 @@ public void getVariationForRolloutWithBucketingId() {
11521152
bucketer,
11531153
mockErrorHandler,
11541154
null,
1155-
null
1155+
mockCmabService
11561156
));
11571157

11581158
FeatureDecision expectedFeatureDecision = new FeatureDecision(
@@ -1307,7 +1307,7 @@ public void getVariationForFeatureReturnHoldoutDecisionForGlobalHoldout() {
13071307

13081308
Bucketer mockBucketer = new Bucketer();
13091309

1310-
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, null);
1310+
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, mockCmabService);
13111311

13121312
Map<String, Object> attributes = new HashMap<>();
13131313
attributes.put("$opt_bucketing_id", "ppid160000");
@@ -1353,7 +1353,7 @@ public void excludedFlagsHoldoutAppliesToAllExceptSpecified() {
13531353

13541354
Bucketer mockBucketer = new Bucketer();
13551355

1356-
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, null);
1356+
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, mockCmabService);
13571357

13581358
Map<String, Object> attributes = new HashMap<>();
13591359
attributes.put("$opt_bucketing_id", "ppid300002");
@@ -1384,7 +1384,7 @@ public void userMeetsHoldoutAudienceConditions() {
13841384

13851385
Bucketer mockBucketer = new Bucketer();
13861386

1387-
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, null);
1387+
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, null, mockCmabService);
13881388

13891389
Map<String, Object> attributes = new HashMap<>();
13901390
attributes.put("$opt_bucketing_id", "ppid543400");

0 commit comments

Comments
 (0)