Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.2.0

- Change position of `activateExperiment` parameter in the method signatures of `getVariableString`, `getVariableBoolean`, `getVariableInteger`, and `getVariableFloat`
- Change `UserExperimentRecord` to `UserProfile`
- Add support for IP anonymization
- Add `NotificationListener` for SDK events
Expand Down
46 changes: 23 additions & 23 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ private void track(@Nonnull String eventName,
//======== live variable getters ========//

public @Nullable String getVariableString(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId) throws UnknownLiveVariableException {
return getVariableString(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
@Nonnull String userId,
boolean activateExperiment) throws UnknownLiveVariableException {
return getVariableString(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
}

public @Nullable String getVariableString(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
@Nonnull Map<String, String> attributes,
boolean activateExperiment)
throws UnknownLiveVariableException {

LiveVariable variable = getLiveVariableOrThrow(projectConfig, variableKey);
Expand Down Expand Up @@ -308,18 +308,18 @@ private void track(@Nonnull String eventName,
}

public @Nullable Boolean getVariableBoolean(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId) throws UnknownLiveVariableException {
return getVariableBoolean(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
@Nonnull String userId,
boolean activateExperiment) throws UnknownLiveVariableException {
return getVariableBoolean(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
}

public @Nullable Boolean getVariableBoolean(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
@Nonnull Map<String, String> attributes,
boolean activateExperiment)
throws UnknownLiveVariableException {

String variableValueString = getVariableString(variableKey, activateExperiment, userId, attributes);
String variableValueString = getVariableString(variableKey, userId, attributes, activateExperiment);
if (variableValueString != null) {
return Boolean.parseBoolean(variableValueString);
}
Expand All @@ -328,18 +328,18 @@ private void track(@Nonnull String eventName,
}

public @Nullable Integer getVariableInteger(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId) throws UnknownLiveVariableException {
return getVariableInteger(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
@Nonnull String userId,
boolean activateExperiment) throws UnknownLiveVariableException {
return getVariableInteger(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
}

public @Nullable Integer getVariableInteger(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
@Nonnull Map<String, String> attributes,
boolean activateExperiment)
throws UnknownLiveVariableException {

String variableValueString = getVariableString(variableKey, activateExperiment, userId, attributes);
String variableValueString = getVariableString(variableKey, userId, attributes, activateExperiment);
if (variableValueString != null) {
try {
return Integer.parseInt(variableValueString);
Expand All @@ -353,18 +353,18 @@ private void track(@Nonnull String eventName,
}

public @Nullable Float getVariableFloat(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId) throws UnknownLiveVariableException {
return getVariableFloat(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
@Nonnull String userId,
boolean activateExperiment) throws UnknownLiveVariableException {
return getVariableFloat(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
}

public @Nullable Float getVariableFloat(@Nonnull String variableKey,
boolean activateExperiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes)
@Nonnull Map<String, String> attributes,
boolean activateExperiment)
throws UnknownLiveVariableException {

String variableValueString = getVariableString(variableKey, activateExperiment, userId, attributes);
String variableValueString = getVariableString(variableKey, userId, attributes, activateExperiment);
if (variableValueString != null) {
try {
return Float.parseFloat(variableValueString);
Expand Down
54 changes: 27 additions & 27 deletions core-api/src/test/java/com/optimizely/ab/OptimizelyTestV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ public void trackDispatchEventThrowsException() throws Exception {
//======== live variable getters tests ========//

/**
* Verify that {@link Optimizely#getVariableString(String, boolean, String)} returns null and logs properly when
* Verify that {@link Optimizely#getVariableString(String, String, boolean)} returns null and logs properly when
* an invalid live variable key is provided and the {@link NoOpErrorHandler} is used.
*/
@Test
Expand All @@ -973,11 +973,11 @@ public void getVariableInvalidVariableKeyNoOpErrorHandler() throws Exception {
.build();

logbackVerifier.expectMessage(Level.ERROR, "Live variable \"invalid_key\" is not in the datafile.");
assertNull(optimizely.getVariableString("invalid_key", false, "userId"));
assertNull(optimizely.getVariableString("invalid_key", "userId", false));
}

/**
* Verify that {@link Optimizely#getVariableString(String, boolean, String)} returns throws an
* Verify that {@link Optimizely#getVariableString(String, String, boolean)} returns throws an
* {@link UnknownLiveVariableException} when an invalid live variable key is provided and the
* {@link RaiseExceptionErrorHandler} is used.
*/
Expand All @@ -993,11 +993,11 @@ public void getVariableInvalidVariableKeyRaiseExceptionErrorHandler() throws Exc
.withErrorHandler(new RaiseExceptionErrorHandler())
.build();

optimizely.getVariableString("invalid_key", false, "userId");
optimizely.getVariableString("invalid_key", "userId", false);
}

/**
* Verify that {@link Optimizely#getVariableString(String, boolean, String, Map)} returns a string live variable
* Verify that {@link Optimizely#getVariableString(String, String, Map, boolean)} returns a string live variable
* value when an proper variable key is provided and dispatches an impression when activateExperiment is true.
*/
@Test
Expand All @@ -1017,14 +1017,14 @@ public void getVariableStringActivateExperimentTrue() throws Exception {
.withErrorHandler(new RaiseExceptionErrorHandler())
.build();

assertThat(optimizely.getVariableString("string_variable", true, "userId",
Collections.singletonMap("browser_type", "chrome")),
assertThat(optimizely.getVariableString("string_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), true),
is("string_var_vtag1"));
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
}

/**
* Verify that {@link Optimizely#getVariableString(String, boolean, String, Map)} returns a string live variable
* Verify that {@link Optimizely#getVariableString(String, String, Map, boolean)} returns a string live variable
* value when an proper variable key is provided and doesn't dispatch an impression when activateExperiment is
* false.
*/
Expand All @@ -1045,14 +1045,14 @@ public void getVariableStringActivateExperimentFalse() throws Exception {
.withErrorHandler(new RaiseExceptionErrorHandler())
.build();

assertThat(optimizely.getVariableString("string_variable", false, "userId",
Collections.singletonMap("browser_type", "chrome")),
assertThat(optimizely.getVariableString("string_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), false),
is("string_var_vtag1"));
verify(mockEventHandler, never()).dispatchEvent(any(LogEvent.class));
}

/**
* Verify that {@link Optimizely#getVariableString(String, boolean, String)} returns the default value of
* Verify that {@link Optimizely#getVariableString(String, String, boolean)} returns the default value of
* a live variable when no experiments are using the live variable.
*/
@Test
Expand All @@ -1065,11 +1065,11 @@ public void getVariableStringReturnsDefaultValueNoExperimentsUsingLiveVariable()
.build();

logbackVerifier.expectMessage(Level.WARN, "No experiment is using variable \"unused_string_variable\".");
assertThat(optimizely.getVariableString("unused_string_variable", true, "userId"), is("unused_variable"));
assertThat(optimizely.getVariableString("unused_string_variable", "userId", true), is("unused_variable"));
}

/**
* Verify that {@link Optimizely#getVariableString(String, boolean, String, Map)} returns the default value when
* Verify that {@link Optimizely#getVariableString(String, String, Map, boolean)} returns the default value when
* a user isn't bucketed into a variation in the experiment.
*/
@Test
Expand All @@ -1086,13 +1086,13 @@ public void getVariableStringReturnsDefaultValueUserNotInVariation() throws Exce
.withBucketing(mockBucketer)
.build();

assertThat(optimizely.getVariableString("string_variable", true, "userId",
Collections.singletonMap("browser_type", "chrome")),
assertThat(optimizely.getVariableString("string_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), true),
is("string_live_variable"));
}

/**
* Verify that {@link Optimizely#getVariableBoolean(String, boolean, String, Map)} returns a boolean live variable
* Verify that {@link Optimizely#getVariableBoolean(String, String, Map, boolean)} returns a boolean live variable
* value when an proper variable key is provided and dispatches an impression when activateExperiment is true.
*/
@Test
Expand All @@ -1111,12 +1111,12 @@ public void getVariableBoolean() throws Exception {
.withBucketing(mockBucketer)
.build();

assertTrue(optimizely.getVariableBoolean("etag1_variable", true, "userId",
Collections.singletonMap("browser_type", "chrome")));
assertTrue(optimizely.getVariableBoolean("etag1_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), true));
}

/**
* Verify that {@link Optimizely#getVariableFloat(String, boolean, String, Map)} returns a float live variable
* Verify that {@link Optimizely#getVariableFloat(String, String, Map, boolean)} returns a float live variable
* value when an proper variable key is provided and dispatches an impression when activateExperiment is true.
*/
@Test
Expand All @@ -1135,14 +1135,14 @@ public void getVariableFloat() throws Exception {
.withBucketing(mockBucketer)
.build();

assertThat(optimizely.getVariableFloat("float_variable", true, "userId",
Collections.singletonMap("browser_type", "chrome")),
assertThat(optimizely.getVariableFloat("float_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), true),
is(5.3f));
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
}

/**
* Verify that {@link Optimizely#getVariableInteger(String, boolean, String, Map)} returns a integer live variable
* Verify that {@link Optimizely#getVariableInteger(String, String, Map, boolean)} returns a integer live variable
* value when an proper variable key is provided and dispatches an impression when activateExperiment is true.
*/
@Test
Expand All @@ -1161,8 +1161,8 @@ public void getVariableInteger() throws Exception {
.withBucketing(mockBucketer)
.build();

assertThat(optimizely.getVariableInteger("integer_variable", true, "userId",
Collections.singletonMap("browser_type", "chrome")),
assertThat(optimizely.getVariableInteger("integer_variable", "userId",
Collections.singletonMap("browser_type", "chrome"), true),
is(10));
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
}
Expand Down Expand Up @@ -1504,7 +1504,7 @@ public void addNotificationListener() throws Exception {

// Check if listener is notified when live variable is accessed
boolean activateExperiment = true;
optimizely.getVariableString("string_variable", activateExperiment, userId, attributes);
optimizely.getVariableString("string_variable", userId, attributes, activateExperiment);
verify(listener, times(2))
.onExperimentActivated(activatedExperiment, userId, attributes, actualVariation);
}
Expand Down Expand Up @@ -1558,7 +1558,7 @@ public void removeNotificationListener() throws Exception {

// Check if listener is notified after a live variable is accessed
boolean activateExperiment = true;
optimizely.getVariableString("string_variable", activateExperiment, userId, attributes);
optimizely.getVariableString("string_variable", userId, attributes, activateExperiment);
verify(listener, never())
.onExperimentActivated(activatedExperiment, userId, attributes, actualVariation);
}
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public void clearNotificationListeners() throws Exception {

// Check if listener is notified after a live variable is accessed
boolean activateExperiment = true;
optimizely.getVariableString("string_variable", activateExperiment, userId, attributes);
optimizely.getVariableString("string_variable", userId, attributes, activateExperiment);
verify(listener, never())
.onExperimentActivated(activatedExperiment, userId, attributes, actualVariation);
}
Expand Down