Skip to content

Commit dab45c2

Browse files
author
Mike Ng
committed
Fix missing UER references.
1 parent a86ab38 commit dab45c2

File tree

7 files changed

+36
-38
lines changed

7 files changed

+36
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
102102

103103
// Do work here that should be done once per Optimizely lifecycle
104104
@VisibleForTesting void initialize() {
105-
bucketer.cleanUserExperimentRecords();
105+
bucketer.cleanUserProfiles();
106106
}
107107

108108
//======== activate calls ========//
@@ -458,7 +458,7 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
458458
return this;
459459
}
460460

461-
public Builder withUserExperimentRecord(UserProfile userProfile) {
461+
public Builder withUserProfile(UserProfile userProfile) {
462462
this.userProfile = userProfile;
463463
return this;
464464
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ private Variation bucketToVariation(@Nonnull Experiment experiment,
112112
String experimentKey = experiment.getKey();
113113
String combinedBucketId = userId + experimentId;
114114

115-
// If a user experiment record instance is present then check it for a saved variation
115+
// If a user profile instance is present then check it for a saved variation
116116
if (userProfile != null) {
117117
String variationKey = userProfile.lookup(userId, experimentKey);
118118
if (variationKey != null) {
119119
logger.info("Returning previously activated variation \"{}\" of experiment \"{}\" "
120-
+ "for user \"{}\" from user experiment record.",
120+
+ "for user \"{}\" from user profile.",
121121
variationKey, experimentKey, userId);
122122
// A variation is stored for this combined bucket id
123123
return projectConfig
@@ -127,7 +127,7 @@ private Variation bucketToVariation(@Nonnull Experiment experiment,
127127
.get(variationKey);
128128
} else {
129129
logger.info("No previously activated variation of experiment \"{}\" "
130-
+ "for user \"{}\" found in user experiment record.",
130+
+ "for user \"{}\" found in user profile.",
131131
experimentKey, userId);
132132
}
133133
}
@@ -145,7 +145,7 @@ private Variation bucketToVariation(@Nonnull Experiment experiment,
145145
logger.info("User \"{}\" is in variation \"{}\" of experiment \"{}\".", userId, variationKey,
146146
experimentKey);
147147

148-
// If a user experiment record is present give it a variation to store
148+
// If a user profile is present give it a variation to store
149149
if (userProfile != null) {
150150
boolean saved = userProfile.save(userId, experiment.getKey(), variationKey);
151151
if (saved) {
@@ -232,7 +232,7 @@ public UserProfile getUserProfile() {
232232
* Gives implementations of {@link UserProfile} a chance to remove records
233233
* of experiments that are deleted or not running.
234234
*/
235-
public void cleanUserExperimentRecords() {
235+
public void cleanUserProfiles() {
236236
if (userProfile != null) {
237237
Map<String, Map<String,String>> records = userProfile.getAllRecords();
238238
if (records != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface UserProfile {
4747
String lookup(String userId, String experimentKey);
4848

4949
/**
50-
* Called when user experiment record should be removed
50+
* Called when user profile should be removed
5151
*
5252
* Records should be removed when an experiment is not running or when an experiment has been
5353
* deleted.

core-api/src/test/java/com/optimizely/ab/OptimizelyBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ public void withDefaultErrorHandler() throws Exception {
102102
}
103103

104104
@Test
105-
public void withUserExperimentRecord() throws Exception {
105+
public void withUserProfile() throws Exception {
106106
UserProfile userProfile = mock(UserProfile.class);
107107
Optimizely optimizelyClient = Optimizely.builder(validConfigJsonV2(), mockEventHandler)
108-
.withUserExperimentRecord(userProfile)
108+
.withUserProfile(userProfile)
109109
.build();
110110

111111
assertThat(optimizelyClient.bucketer.getUserProfile(), is(userProfile));

core-api/src/test/java/com/optimizely/ab/OptimizelyTestV1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void initializationOccursForBucketerWhenBuildingOptly() throws Exception
159159
.withErrorHandler(mockErrorHandler)
160160
.build();
161161

162-
verify(mockBucketer).cleanUserExperimentRecords();
162+
verify(mockBucketer).cleanUserProfiles();
163163
}
164164

165165
/**

core-api/src/test/java/com/optimizely/ab/OptimizelyTestV2.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@
3131
import com.optimizely.ab.error.RaiseExceptionErrorHandler;
3232
import com.optimizely.ab.event.EventHandler;
3333
import com.optimizely.ab.event.LogEvent;
34-
import com.optimizely.ab.event.internal.BuildVersionInfo;
3534
import com.optimizely.ab.event.internal.EventBuilder;
3635
import com.optimizely.ab.event.internal.EventBuilderV2;
37-
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;
3836
import com.optimizely.ab.internal.LogbackVerifier;
3937
import com.optimizely.ab.internal.ProjectValidationUtils;
4038

@@ -161,7 +159,7 @@ public void initializationOccursForBucketerWhenBuildingOptly() throws Exception
161159
.withErrorHandler(mockErrorHandler)
162160
.build();
163161

164-
verify(mockBucketer).cleanUserExperimentRecords();
162+
verify(mockBucketer).cleanUserProfiles();
165163
}
166164

167165
/**

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,10 @@ public void bucketUserNotInOverlappingGroupExperiment() throws Exception {
449449
* Verify that {@link Bucketer#bucket(Experiment,String)} saves a variation of an experiment for a user
450450
* when a {@link UserProfile} is present.
451451
*/
452-
@Test public void bucketUserSaveActivationWithUserExperimentRecord() throws Exception {
452+
@Test public void bucketUserSaveActivationWithUserProfile() throws Exception {
453453
final AtomicInteger bucketValue = new AtomicInteger();
454454
UserProfile userProfile = mock(UserProfile.class);
455-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
455+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
456456
bucketValue.set(3000);
457457

458458
ProjectConfig projectConfig = validProjectConfigV2();
@@ -474,10 +474,10 @@ public void bucketUserNotInOverlappingGroupExperiment() throws Exception {
474474
* Verify that {@link Bucketer#bucket(Experiment,String)} logs correctly
475475
* when a {@link UserProfile} is present and fails to save an activation.
476476
*/
477-
@Test public void bucketUserSaveActivationFailWithUserExperimentRecord() throws Exception {
477+
@Test public void bucketUserSaveActivationFailWithUserProfile() throws Exception {
478478
final AtomicInteger bucketValue = new AtomicInteger();
479479
UserProfile userProfile = mock(UserProfile.class);
480-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
480+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
481481
bucketValue.set(3000);
482482

483483
ProjectConfig projectConfig = validProjectConfigV2();
@@ -499,10 +499,10 @@ public void bucketUserNotInOverlappingGroupExperiment() throws Exception {
499499
* Verify that {@link Bucketer#bucket(Experiment,String)} returns a variation that is
500500
* stored in the provided {@link UserProfile}.
501501
*/
502-
@Test public void bucketUserRestoreActivationWithUserExperimentRecord() throws Exception {
502+
@Test public void bucketUserRestoreActivationWithUserProfile() throws Exception {
503503
final AtomicInteger bucketValue = new AtomicInteger();
504504
UserProfile userProfile = mock(UserProfile.class);
505-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
505+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
506506
bucketValue.set(3000);
507507

508508
ProjectConfig projectConfig = validProjectConfigV2();
@@ -516,7 +516,7 @@ public void bucketUserNotInOverlappingGroupExperiment() throws Exception {
516516

517517
logbackVerifier.expectMessage(Level.INFO,
518518
"Returning previously activated variation \"e2_vtag1\" of experiment \"group_etag2\""
519-
+ " for user \"blah\" from user experiment record.");
519+
+ " for user \"blah\" from user profile.");
520520

521521
verify(userProfile).lookup("blah", groupExperiment.getKey());
522522
}
@@ -525,10 +525,10 @@ public void bucketUserNotInOverlappingGroupExperiment() throws Exception {
525525
* Verify {@link Bucketer#bucket(Experiment,String)} handles a present {@link UserProfile}
526526
* returning null when looking up a variation.
527527
*/
528-
@Test public void bucketUserRestoreActivationNullWithUserExperimentRecord() throws Exception {
528+
@Test public void bucketUserRestoreActivationNullWithUserProfile() throws Exception {
529529
final AtomicInteger bucketValue = new AtomicInteger();
530530
UserProfile userProfile = mock(UserProfile.class);
531-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
531+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
532532
bucketValue.set(3000);
533533

534534
ProjectConfig projectConfig = validProjectConfigV2();
@@ -541,53 +541,53 @@ public void bucketUserNotInOverlappingGroupExperiment() throws Exception {
541541
assertThat(algorithm.bucket(groupExperiment, "blah"), is(variation));
542542

543543
logbackVerifier.expectMessage(Level.INFO, "No previously activated variation of experiment " +
544-
"\"group_etag2\" for user \"blah\" found in user experiment record.");
544+
"\"group_etag2\" for user \"blah\" found in user profile.");
545545
verify(userProfile).lookup("blah", groupExperiment.getKey());
546546
}
547547

548548
/**
549-
* Verify {@link Bucketer#cleanUserExperimentRecords()} handles a null {@link UserProfile}.
549+
* Verify {@link Bucketer#cleanUserProfiles()} handles a null {@link UserProfile}.
550550
*/
551551
@Test
552-
public void nullUserExperimentRecordWhenCleaning() {
552+
public void nullUserProfileWhenCleaning() {
553553
final AtomicInteger bucketValue = new AtomicInteger();
554554
Bucketer algorithm = mockBucketAlgorithm(bucketValue);
555555
bucketValue.set(3000);
556556
try {
557-
algorithm.cleanUserExperimentRecords();
557+
algorithm.cleanUserProfiles();
558558
} catch (NullPointerException e) {
559559
fail();
560560
}
561561
}
562562

563563
/**
564-
* Verify {@link Bucketer#cleanUserExperimentRecords()} handles a null returned from
564+
* Verify {@link Bucketer#cleanUserProfiles()} handles a null returned from
565565
* {@link UserProfile#getAllRecords()}.
566566
*/
567567
@Test
568-
public void nullUserExperimentRecords() {
568+
public void nullUserProfiles() {
569569
final AtomicInteger bucketValue = new AtomicInteger();
570570
UserProfile userProfile = mock(UserProfile.class);
571-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
571+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
572572
bucketValue.set(3000);
573573

574574
when(userProfile.getAllRecords()).thenReturn(null);
575575
try {
576-
algorithm.cleanUserExperimentRecords();
576+
algorithm.cleanUserProfiles();
577577
} catch (NullPointerException e) {
578578
fail();
579579
}
580580
}
581581

582582
/**
583-
* Verify {@link Bucketer#cleanUserExperimentRecords()} removes experiments
583+
* Verify {@link Bucketer#cleanUserProfiles()} removes experiments
584584
* that are no longer in the {@link ProjectConfig}.
585585
*/
586586
@Test
587587
public void cleanRemovesRecordsOfExperimentsThatNoLongerExist() {
588588
final AtomicInteger bucketValue = new AtomicInteger();
589589
UserProfile userProfile = mock(UserProfile.class);
590-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
590+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
591591
bucketValue.set(3000);
592592

593593
Map<String,Map<String,String>> records = new HashMap<String, Map<String, String>>();
@@ -596,20 +596,20 @@ public void cleanRemovesRecordsOfExperimentsThatNoLongerExist() {
596596
records.put("blah", activation);
597597
when(userProfile.getAllRecords()).thenReturn(records);
598598

599-
algorithm.cleanUserExperimentRecords();
599+
algorithm.cleanUserProfiles();
600600

601601
verify(userProfile).remove("blah", "exp1");
602602
}
603603

604604
/**
605-
* Verify {@link Bucketer#cleanUserExperimentRecords()} removes experiments
605+
* Verify {@link Bucketer#cleanUserProfiles()} removes experiments
606606
* that are paused in the {@link ProjectConfig}.
607607
*/
608608
@Test
609609
public void cleanRemovesRecordsOfExperimentsThatAreNotRunning() {
610610
final AtomicInteger bucketValue = new AtomicInteger();
611611
UserProfile userProfile = mock(UserProfile.class);
612-
Bucketer algorithm = mockUserExperimentRecordAlgorithm(bucketValue, userProfile);
612+
Bucketer algorithm = mockUserProfileAlgorithm(bucketValue, userProfile);
613613
bucketValue.set(3000);
614614

615615
Map<String,Map<String,String>> records = new HashMap<String, Map<String, String>>();
@@ -618,7 +618,7 @@ public void cleanRemovesRecordsOfExperimentsThatAreNotRunning() {
618618
records.put("blah", activation);
619619
when(userProfile.getAllRecords()).thenReturn(records);
620620

621-
algorithm.cleanUserExperimentRecords();
621+
algorithm.cleanUserProfiles();
622622

623623
verify(userProfile).remove("blah", "exp1");
624624
}
@@ -647,7 +647,7 @@ int generateBucketValue(int hashCode) {
647647
* @param bucketValue the expected bucket value holder
648648
* @return the mock bucket algorithm
649649
*/
650-
private Bucketer mockUserExperimentRecordAlgorithm(final AtomicInteger bucketValue, final UserProfile userProfile) {
650+
private Bucketer mockUserProfileAlgorithm(final AtomicInteger bucketValue, final UserProfile userProfile) {
651651
return new Bucketer(validProjectConfigV2(), userProfile) {
652652
@Override
653653
int generateBucketValue(int hashCode) {

0 commit comments

Comments
 (0)