Skip to content

Commit 7a8868a

Browse files
mnoman09mikeproeng37
authored andcommitted
Removed overloaded methods of track that were taking long Event value (#186)
1 parent e4c0913 commit 7a8868a

File tree

3 files changed

+41
-69
lines changed

3 files changed

+41
-69
lines changed

android-sdk/src/androidTest/java/com/optimizely/ab/android/sdk/OptimizelyClientTest.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.optimizely.ab.config.parser.ConfigParseException;
3030
import com.optimizely.ab.event.EventHandler;
3131
import com.optimizely.ab.event.LogEvent;
32+
import com.optimizely.ab.internal.ReservedEventKey;
3233
import com.optimizely.ab.notification.ActivateNotificationListener;
3334
import com.optimizely.ab.notification.NotificationCenter;
3435
import com.optimizely.ab.notification.NotificationListener;
@@ -601,7 +602,10 @@ public void testGoodForcedTrackEventVal() {
601602

602603
ProjectConfig config = optimizely.getProjectConfig();
603604

604-
optimizelyClient.track("test_event", GENERIC_USER_ID, 1L);
605+
optimizelyClient.track("test_event",
606+
GENERIC_USER_ID,
607+
Collections.<String, String>emptyMap(),
608+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
605609

606610
verifyZeroInteractions(logger);
607611

@@ -636,28 +640,37 @@ public void testGoodForcedTrackEventVal() {
636640
public void testGoodTrackEventVal() {
637641
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely,
638642
logger);
639-
optimizelyClient.track("test_event", GENERIC_USER_ID, 1L);
643+
optimizelyClient.track("test_event",
644+
GENERIC_USER_ID,
645+
Collections.<String, String>emptyMap(),
646+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
640647
verifyZeroInteractions(logger);
641648
}
642649

643650
@Test
644651
public void testBadTrackEventVal() {
645652
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
646-
optimizelyClient.track("event1", GENERIC_USER_ID, 1L);
647-
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {} " +
648-
"with value {}", "event1", GENERIC_USER_ID, 1L);
653+
optimizelyClient.track("event1",
654+
GENERIC_USER_ID,
655+
Collections.<String, String>emptyMap(),
656+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
657+
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {}" +
658+
" with attributes and event tags", "event1", GENERIC_USER_ID);
649659
}
650660

651661
@Test
652662
public void testBadForcedTrackEventVal() {
653663
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
654-
664+
final HashMap<String, String> attributes = new HashMap<>();
655665
boolean didSetForced = optimizelyClient.setForcedVariation(FEATURE_ANDROID_EXPERIMENT_KEY, GENERIC_USER_ID, "var_2");
656666

657667
assertFalse(didSetForced);
658-
optimizelyClient.track("event1", GENERIC_USER_ID, 1L);
659-
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {} " +
660-
"with value {}", "event1", GENERIC_USER_ID, 1L);
668+
optimizelyClient.track("event1",
669+
GENERIC_USER_ID,
670+
attributes,
671+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
672+
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {}" +
673+
" with attributes and event tags", "event1", GENERIC_USER_ID);
661674

662675
Variation v = optimizelyClient.getForcedVariation(FEATURE_ANDROID_EXPERIMENT_KEY, GENERIC_USER_ID);
663676
assertNull(v);
@@ -674,7 +687,8 @@ public void testGoodTrackAttributeEventVal() {
674687
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely,
675688
logger);
676689
final HashMap<String, String> attributes = new HashMap<>();
677-
optimizelyClient.track("test_event", GENERIC_USER_ID, attributes, 1L);
690+
optimizelyClient.track("test_event", GENERIC_USER_ID, attributes,
691+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
678692
verifyZeroInteractions(logger);
679693
}
680694

@@ -690,7 +704,10 @@ public void testGoodForcedTrackAttributeEventVal() {
690704

691705
ProjectConfig config = optimizelyClient.getProjectConfig();
692706

693-
optimizelyClient.track("test_event", GENERIC_USER_ID, attributes, 1L);
707+
optimizelyClient.track("test_event",
708+
GENERIC_USER_ID,
709+
attributes,
710+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
694711

695712
verifyZeroInteractions(logger);
696713

@@ -725,9 +742,10 @@ public void testGoodForcedTrackAttributeEventVal() {
725742
public void testBadTrackAttributeEventVal() {
726743
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
727744
final HashMap<String, String> attributes = new HashMap<>();
728-
optimizelyClient.track("event1", GENERIC_USER_ID, attributes, 1L);
729-
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {} " +
730-
"with value {} and attributes", "event1", GENERIC_USER_ID, 1L);
745+
optimizelyClient.track("event1", GENERIC_USER_ID, attributes,
746+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
747+
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {}" +
748+
" with attributes and event tags", "event1", GENERIC_USER_ID);
731749
}
732750

733751
@Test
@@ -739,9 +757,10 @@ public void testBadForcedTrackAttributeEventVal() {
739757

740758
assertFalse(didSetForced);
741759

742-
optimizelyClient.track("event1", GENERIC_USER_ID, attributes, 1L);
743-
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {} " +
744-
"with value {} and attributes", "event1", GENERIC_USER_ID, 1L);
760+
optimizelyClient.track("event1", GENERIC_USER_ID, attributes,
761+
Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
762+
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {}" +
763+
" with attributes and event tags", "event1", GENERIC_USER_ID);
745764

746765
Variation v = optimizelyClient.getForcedVariation(FEATURE_ANDROID_EXPERIMENT_KEY, GENERIC_USER_ID);
747766
assertNull(v);

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyClient.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -212,45 +212,6 @@ public void track(@NonNull String eventName,
212212
}
213213
}
214214

215-
/**
216-
* Track an event for a user
217-
* @deprecated see {@link Optimizely#track(String, String, Map, Map)} and pass in revenue values as event tags instead.
218-
* @param eventName the name of the event
219-
* @param userId the user id
220-
* @param eventValue a value to tie to the event
221-
*/
222-
public void track(@NonNull String eventName,
223-
@NonNull String userId,
224-
long eventValue) throws UnknownEventTypeException {
225-
if (isValid()) {
226-
optimizely.track(eventName, userId, getDefaultAttributes(), Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
227-
} else {
228-
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
229-
" with value {}", eventName, userId, eventValue);
230-
}
231-
}
232-
233-
/**
234-
* Track an event for a user with attributes and a value
235-
* @see Optimizely#track(String, String, Map, Map)
236-
* @deprecated see {@link Optimizely#track(String, String, Map, Map)} and pass in revenue values as event tags instead.
237-
* @param eventName the String name of the event
238-
* @param userId the String user id
239-
* @param attributes the attributes of the event
240-
* @param eventValue the value of the event
241-
*/
242-
public void track(@NonNull String eventName,
243-
@NonNull String userId,
244-
@NonNull Map<String, String> attributes,
245-
long eventValue) {
246-
if (isValid()) {
247-
optimizely.track(eventName, userId, getAllAttributes(attributes), Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
248-
} else {
249-
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
250-
" with value {} and attributes", eventName, userId, eventValue);
251-
}
252-
}
253-
254215
/**
255216
* Get the variation the user is bucketed into
256217
* @see Optimizely#getVariation(Experiment, String)

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyClientTest.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,20 @@ public void testBadTrack2() {
141141
}
142142

143143
@Test
144-
public void testBadTrack3() {
145-
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
146-
optimizelyClient.track("event1", "1", 1L);
147-
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {} " +
148-
"with value {}", "event1", "1", 1L);
149-
}
150-
151-
@Test
152-
public void testGoodTrack4() {
144+
public void testGoodTrack3() {
153145
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
154146
final HashMap<String, String> attributes = new HashMap<>();
155-
optimizelyClient.track("event1", "1", attributes, 1L);
147+
optimizelyClient.track("event1", "1", attributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
156148
Map<String, String> defaultAttributes = new HashMap<>();
157149
verify(optimizely).track("event1", "1", defaultAttributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L)); }
158150

159151
@Test
160152
public void testBadTrack4() {
161153
OptimizelyClient optimizelyClient = new OptimizelyClient(null, logger);
162154
final HashMap<String, String> attributes = new HashMap<>();
163-
optimizelyClient.track("event1", "1", attributes, 1L);
164-
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {} " +
165-
"with value {} and attributes", "event1", "1", 1L);
155+
optimizelyClient.track("event1", "1", attributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), 1L));
156+
verify(logger).warn("Optimizely is not initialized, could not track event {} for user {}" +
157+
" with attributes and event tags", "event1", "1");
166158
}
167159

168160
@Test

0 commit comments

Comments
 (0)