Skip to content

Commit bbbccca

Browse files
authored
Merge pull request #85 from optimizely/devel
Release 1.6.0
2 parents c313636 + a7a1652 commit bbbccca

File tree

110 files changed

+1522
-912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1522
-912
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jdk:
66
install: true
77
script:
88
- "./gradlew clean"
9+
- "./gradlew exhaustiveTest"
910
- "if [[ -n $TRAVIS_TAG ]]; then
1011
./gradlew ship;
1112
else

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 1.6.0
2+
3+
March 17, 2017
4+
5+
- Add event tags to `track` API and include in the event payload
6+
- Deprecates the `eventValue` parameter from the `track` method. Should use event tags to pass in event value instead
7+
- Gracefully handle a null attributes parameter
8+
- Gracefully handle a null/empty datafile when using the Gson parser
9+
110
## 1.5.0
211

312
February 16, 2017

core-api/src/jmh/java/com/optimizely/ab/BenchmarkUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/jmh/java/com/optimizely/ab/OptimizelyBenchmark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/jmh/java/com/optimizely/ab/OptimizelyBuilderBenchmark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+44-71
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -38,7 +38,9 @@
3838
import com.optimizely.ab.event.internal.EventBuilderV1;
3939
import com.optimizely.ab.event.internal.EventBuilderV2;
4040
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;
41+
import com.optimizely.ab.internal.EventTagUtils;
4142
import com.optimizely.ab.internal.ProjectValidationUtils;
43+
import com.optimizely.ab.internal.ReservedEventKey;
4244
import com.optimizely.ab.notification.NotificationListener;
4345
import com.optimizely.ab.notification.NotificationBroadcaster;
4446

@@ -117,22 +119,9 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
117119
return activate(experimentKey, userId, Collections.<String, String>emptyMap());
118120
}
119121

120-
public @Nullable Variation activate(@Nonnull String experimentKey,
121-
@Nonnull String userId,
122-
@CheckForNull String sessionId) throws UnknownExperimentException {
123-
return activate(experimentKey, userId, Collections.<String, String>emptyMap(), sessionId);
124-
}
125-
126122
public @Nullable Variation activate(@Nonnull String experimentKey,
127123
@Nonnull String userId,
128124
@Nonnull Map<String, String> attributes) throws UnknownExperimentException {
129-
return activate(experimentKey, userId, attributes, null);
130-
}
131-
132-
public @Nullable Variation activate(@Nonnull String experimentKey,
133-
@Nonnull String userId,
134-
@Nonnull Map<String, String> attributes,
135-
@CheckForNull String sessionId) throws UnknownExperimentException {
136125

137126
if (!validateUserId(userId)) {
138127
logger.info("Not activating user for experiment \"{}\".", experimentKey);
@@ -148,42 +137,27 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
148137
return null;
149138
}
150139

151-
return activate(currentConfig, experiment, userId, attributes, sessionId);
140+
return activate(currentConfig, experiment, userId, attributes);
152141
}
153142

154143
public @Nullable Variation activate(@Nonnull Experiment experiment,
155144
@Nonnull String userId) {
156145
return activate(experiment, userId, Collections.<String, String>emptyMap());
157146
}
158147

159-
public @Nullable Variation activate(@Nonnull Experiment experiment,
160-
@Nonnull String userId,
161-
@CheckForNull String sessionId) {
162-
return activate(experiment, userId, Collections.<String, String>emptyMap(), sessionId);
163-
}
164-
165148
public @Nullable Variation activate(@Nonnull Experiment experiment,
166149
@Nonnull String userId,
167150
@Nonnull Map<String, String> attributes) {
168151

169-
return activate(experiment, userId, attributes, null);
170-
}
171-
172-
public @Nullable Variation activate(@Nonnull Experiment experiment,
173-
@Nonnull String userId,
174-
@Nonnull Map<String, String> attributes,
175-
@CheckForNull String sessionId) {
176-
177152
ProjectConfig currentConfig = getProjectConfig();
178153

179-
return activate(currentConfig, experiment, userId, attributes, sessionId);
154+
return activate(currentConfig, experiment, userId, attributes);
180155
}
181156

182157
private @Nullable Variation activate(@Nonnull ProjectConfig projectConfig,
183158
@Nonnull Experiment experiment,
184159
@Nonnull String userId,
185-
@Nonnull Map<String, String> attributes,
186-
@CheckForNull String sessionId) {
160+
@Nonnull Map<String, String> attributes) {
187161
// determine whether all the given attributes are present in the project config. If not, filter out the unknown
188162
// attributes.
189163
attributes = filterAttributes(projectConfig, attributes);
@@ -202,7 +176,7 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
202176

203177
if (experiment.isRunning()) {
204178
LogEvent impressionEvent = eventBuilder.createImpressionEvent(projectConfig, experiment, variation, userId,
205-
attributes, sessionId);
179+
attributes);
206180
logger.info("Activating user \"{}\" in experiment \"{}\".", userId, experiment.getKey());
207181
logger.debug(
208182
"Dispatching impression event to URL {} with params {} and payload \"{}\".",
@@ -225,61 +199,39 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
225199

226200
public void track(@Nonnull String eventName,
227201
@Nonnull String userId) throws UnknownEventTypeException {
228-
track(eventName, userId, Collections.<String, String>emptyMap(), null, null);
229-
}
230-
231-
public void track(@Nonnull String eventName,
232-
@Nonnull String userId,
233-
@CheckForNull String sessionId) throws UnknownEventTypeException {
234-
track(eventName, userId, Collections.<String, String>emptyMap(), null, sessionId);
202+
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
235203
}
236204

237205
public void track(@Nonnull String eventName,
238206
@Nonnull String userId,
239207
@Nonnull Map<String, String> attributes) throws UnknownEventTypeException {
240-
track(eventName, userId, attributes, null, null);
241-
}
242-
243-
public void track(@Nonnull String eventName,
244-
@Nonnull String userId,
245-
@Nonnull Map<String, String> attributes,
246-
@CheckForNull String sessionId) throws UnknownEventTypeException {
247-
track(eventName, userId, attributes, null, sessionId);
208+
track(eventName, userId, attributes, Collections.<String, String>emptyMap());
248209
}
249210

211+
/**
212+
* @deprecated see {@link #track(String, String, Map)} and pass in the revenue value as an event tag instead.
213+
*/
250214
public void track(@Nonnull String eventName,
251215
@Nonnull String userId,
252216
long eventValue) throws UnknownEventTypeException {
253-
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue);
254-
}
255-
256-
public void track(@Nonnull String eventName,
257-
@Nonnull String userId,
258-
long eventValue,
259-
@CheckForNull String sessionId) throws UnknownEventTypeException {
260-
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue, sessionId);
217+
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.singletonMap(
218+
ReservedEventKey.REVENUE.toString(), eventValue));
261219
}
262220

221+
/**
222+
* @deprecated see {@link #track(String, String, Map, long)} and pass in the revenue value as an event tag instead.
223+
*/
263224
public void track(@Nonnull String eventName,
264225
@Nonnull String userId,
265226
@Nonnull Map<String, String> attributes,
266227
long eventValue) throws UnknownEventTypeException {
267-
track(eventName, userId, attributes, (Long)eventValue, null);
228+
track(eventName, userId, attributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
268229
}
269230

270231
public void track(@Nonnull String eventName,
271-
@Nonnull String userId,
272-
@Nonnull Map<String, String> attributes,
273-
long eventValue,
274-
@CheckForNull String sessionId) throws UnknownEventTypeException {
275-
track(eventName, userId, attributes, (Long)eventValue, sessionId);
276-
}
277-
278-
private void track(@Nonnull String eventName,
279232
@Nonnull String userId,
280233
@Nonnull Map<String, String> attributes,
281-
@CheckForNull Long eventValue,
282-
@CheckForNull String sessionId) throws UnknownEventTypeException {
234+
@Nonnull Map<String, ?> eventTags) throws UnknownEventTypeException {
283235

284236
ProjectConfig currentConfig = getProjectConfig();
285237

@@ -294,10 +246,18 @@ private void track(@Nonnull String eventName,
294246
// attributes.
295247
attributes = filterAttributes(currentConfig, attributes);
296248

249+
Long eventValue = null;
250+
if (eventTags == null) {
251+
logger.warn("Event tags is null when non-null was expected. Defaulting to an empty event tags map.");
252+
eventTags = Collections.<String, String>emptyMap();
253+
} else {
254+
eventValue = EventTagUtils.getRevenueValue(eventTags);
255+
}
256+
297257
// create the conversion event request parameters, then dispatch
298258
LogEvent conversionEvent = eventBuilder.createConversionEvent(currentConfig, bucketer, userId,
299259
eventType.getId(), eventType.getKey(), attributes,
300-
eventValue, sessionId);
260+
eventTags);
301261

302262
if (conversionEvent == null) {
303263
logger.info("There are no valid experiments for event \"{}\" to track.", eventName);
@@ -498,6 +458,13 @@ private void track(@Nonnull String eventName,
498458
* @return a {@link ProjectConfig} instance given a json string
499459
*/
500460
private static ProjectConfig getProjectConfig(String datafile) throws ConfigParseException {
461+
if (datafile == null) {
462+
throw new ConfigParseException("Unable to parse null datafile.");
463+
}
464+
if (datafile.length() == 0) {
465+
throw new ConfigParseException("Unable to parse empty datafile.");
466+
}
467+
501468
return DefaultConfigParser.getInstance().parseProjectConfig(datafile);
502469
}
503470

@@ -624,10 +591,16 @@ private LiveVariable getLiveVariableOrThrow(ProjectConfig projectConfig, String
624591
*
625592
* @param projectConfig the current project config
626593
* @param attributes the attributes map to validate and potentially filter
627-
* @return the filtered attributes map (containing only attributes that are present in the project config)
628-
*
594+
* @return the filtered attributes map (containing only attributes that are present in the project config) or an
595+
* empty map if a null attributes object is passed in
629596
*/
630-
private Map<String, String> filterAttributes(ProjectConfig projectConfig, Map<String, String> attributes) {
597+
private Map<String, String> filterAttributes(@Nonnull ProjectConfig projectConfig,
598+
@Nonnull Map<String, String> attributes) {
599+
if (attributes == null) {
600+
logger.warn("Attributes is null when non-null was expected. Defaulting to an empty attributes map.");
601+
return Collections.<String, String>emptyMap();
602+
}
603+
631604
List<String> unknownAttributes = null;
632605

633606
Map<String, Attribute> attributeKeyMapping = projectConfig.getAttributeKeyMapping();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/annotations/VisibleForTesting.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Attribute.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/EventType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Experiment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/Group.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/IdKeyMapped.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/IdMapped.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/LiveVariable.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

core-api/src/main/java/com/optimizely/ab/config/LiveVariableUsageInstance.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016, Optimizely and contributors
3+
* Copyright 2016-2017, Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)