Skip to content

Commit f180ac5

Browse files
author
Vignesh Raja
authored
Change position of activateExperiment (#46)
1 parent 54b7b3d commit f180ac5

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 1.2.0
22

3+
- Change position of `activateExperiment` parameter in the method signatures of `getVariableString`, `getVariableBoolean`, `getVariableInteger`, and `getVariableFloat`
34
- Change `UserExperimentRecord` to `UserProfile`
45
- Add support for IP anonymization
56
- Add `NotificationListener` for SDK events

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ private void track(@Nonnull String eventName,
263263
//======== live variable getters ========//
264264

265265
public @Nullable String getVariableString(@Nonnull String variableKey,
266-
boolean activateExperiment,
267-
@Nonnull String userId) throws UnknownLiveVariableException {
268-
return getVariableString(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
266+
@Nonnull String userId,
267+
boolean activateExperiment) throws UnknownLiveVariableException {
268+
return getVariableString(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
269269
}
270270

271271
public @Nullable String getVariableString(@Nonnull String variableKey,
272-
boolean activateExperiment,
273272
@Nonnull String userId,
274-
@Nonnull Map<String, String> attributes)
273+
@Nonnull Map<String, String> attributes,
274+
boolean activateExperiment)
275275
throws UnknownLiveVariableException {
276276

277277
LiveVariable variable = getLiveVariableOrThrow(projectConfig, variableKey);
@@ -308,18 +308,18 @@ private void track(@Nonnull String eventName,
308308
}
309309

310310
public @Nullable Boolean getVariableBoolean(@Nonnull String variableKey,
311-
boolean activateExperiment,
312-
@Nonnull String userId) throws UnknownLiveVariableException {
313-
return getVariableBoolean(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
311+
@Nonnull String userId,
312+
boolean activateExperiment) throws UnknownLiveVariableException {
313+
return getVariableBoolean(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
314314
}
315315

316316
public @Nullable Boolean getVariableBoolean(@Nonnull String variableKey,
317-
boolean activateExperiment,
318317
@Nonnull String userId,
319-
@Nonnull Map<String, String> attributes)
318+
@Nonnull Map<String, String> attributes,
319+
boolean activateExperiment)
320320
throws UnknownLiveVariableException {
321321

322-
String variableValueString = getVariableString(variableKey, activateExperiment, userId, attributes);
322+
String variableValueString = getVariableString(variableKey, userId, attributes, activateExperiment);
323323
if (variableValueString != null) {
324324
return Boolean.parseBoolean(variableValueString);
325325
}
@@ -328,18 +328,18 @@ private void track(@Nonnull String eventName,
328328
}
329329

330330
public @Nullable Integer getVariableInteger(@Nonnull String variableKey,
331-
boolean activateExperiment,
332-
@Nonnull String userId) throws UnknownLiveVariableException {
333-
return getVariableInteger(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
331+
@Nonnull String userId,
332+
boolean activateExperiment) throws UnknownLiveVariableException {
333+
return getVariableInteger(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
334334
}
335335

336336
public @Nullable Integer getVariableInteger(@Nonnull String variableKey,
337-
boolean activateExperiment,
338337
@Nonnull String userId,
339-
@Nonnull Map<String, String> attributes)
338+
@Nonnull Map<String, String> attributes,
339+
boolean activateExperiment)
340340
throws UnknownLiveVariableException {
341341

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

355355
public @Nullable Float getVariableFloat(@Nonnull String variableKey,
356-
boolean activateExperiment,
357-
@Nonnull String userId) throws UnknownLiveVariableException {
358-
return getVariableFloat(variableKey, activateExperiment, userId, Collections.<String, String>emptyMap());
356+
@Nonnull String userId,
357+
boolean activateExperiment) throws UnknownLiveVariableException {
358+
return getVariableFloat(variableKey, userId, Collections.<String, String>emptyMap(), activateExperiment);
359359
}
360360

361361
public @Nullable Float getVariableFloat(@Nonnull String variableKey,
362-
boolean activateExperiment,
363362
@Nonnull String userId,
364-
@Nonnull Map<String, String> attributes)
363+
@Nonnull Map<String, String> attributes,
364+
boolean activateExperiment)
365365
throws UnknownLiveVariableException {
366366

367-
String variableValueString = getVariableString(variableKey, activateExperiment, userId, attributes);
367+
String variableValueString = getVariableString(variableKey, userId, attributes, activateExperiment);
368368
if (variableValueString != null) {
369369
try {
370370
return Float.parseFloat(variableValueString);

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public void trackDispatchEventThrowsException() throws Exception {
960960
//======== live variable getters tests ========//
961961

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

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

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

996-
optimizely.getVariableString("invalid_key", false, "userId");
996+
optimizely.getVariableString("invalid_key", "userId", false);
997997
}
998998

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

1020-
assertThat(optimizely.getVariableString("string_variable", true, "userId",
1021-
Collections.singletonMap("browser_type", "chrome")),
1020+
assertThat(optimizely.getVariableString("string_variable", "userId",
1021+
Collections.singletonMap("browser_type", "chrome"), true),
10221022
is("string_var_vtag1"));
10231023
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
10241024
}
10251025

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

1048-
assertThat(optimizely.getVariableString("string_variable", false, "userId",
1049-
Collections.singletonMap("browser_type", "chrome")),
1048+
assertThat(optimizely.getVariableString("string_variable", "userId",
1049+
Collections.singletonMap("browser_type", "chrome"), false),
10501050
is("string_var_vtag1"));
10511051
verify(mockEventHandler, never()).dispatchEvent(any(LogEvent.class));
10521052
}
10531053

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

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

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

1089-
assertThat(optimizely.getVariableString("string_variable", true, "userId",
1090-
Collections.singletonMap("browser_type", "chrome")),
1089+
assertThat(optimizely.getVariableString("string_variable", "userId",
1090+
Collections.singletonMap("browser_type", "chrome"), true),
10911091
is("string_live_variable"));
10921092
}
10931093

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

1114-
assertTrue(optimizely.getVariableBoolean("etag1_variable", true, "userId",
1115-
Collections.singletonMap("browser_type", "chrome")));
1114+
assertTrue(optimizely.getVariableBoolean("etag1_variable", "userId",
1115+
Collections.singletonMap("browser_type", "chrome"), true));
11161116
}
11171117

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

1138-
assertThat(optimizely.getVariableFloat("float_variable", true, "userId",
1139-
Collections.singletonMap("browser_type", "chrome")),
1138+
assertThat(optimizely.getVariableFloat("float_variable", "userId",
1139+
Collections.singletonMap("browser_type", "chrome"), true),
11401140
is(5.3f));
11411141
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
11421142
}
11431143

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

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

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

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

16121612
// Check if listener is notified after a live variable is accessed
16131613
boolean activateExperiment = true;
1614-
optimizely.getVariableString("string_variable", activateExperiment, userId, attributes);
1614+
optimizely.getVariableString("string_variable", userId, attributes, activateExperiment);
16151615
verify(listener, never())
16161616
.onExperimentActivated(activatedExperiment, userId, attributes, actualVariation);
16171617
}

0 commit comments

Comments
 (0)