Skip to content

Commit 872f01e

Browse files
committed
Add trackImpressions to Split DTO
1 parent 8d8e161 commit 872f01e

File tree

6 files changed

+165
-5
lines changed

6 files changed

+165
-5
lines changed

src/main/java/io/split/android/client/dtos/Split.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ public class Split {
4949
@Nullable
5050
@SerializedName("sets")
5151
public Set<String> sets;
52+
53+
@SerializedName("trackImpressions")
54+
public boolean trackImpressions = true;
5255
}

src/main/java/io/split/android/engine/experiments/ParsedSplit.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class ParsedSplit {
2323
private final int mAlgo;
2424
private final Map<String, String> mConfigurations;
2525
private final Set<String> mSets;
26+
private final boolean mTrackImpressions;
2627

2728
public ParsedSplit(
2829
String feature,
@@ -36,7 +37,8 @@ public ParsedSplit(
3637
int trafficAllocationSeed,
3738
int algo,
3839
Map<String, String> configurations,
39-
Set<String> sets
40+
Set<String> sets,
41+
boolean trackImpressions
4042
) {
4143
mSplit = feature;
4244
mSeed = seed;
@@ -47,6 +49,7 @@ public ParsedSplit(
4749
mChangeNumber = changeNumber;
4850
mAlgo = algo;
4951
mConfigurations = configurations;
52+
mTrackImpressions = trackImpressions;
5053

5154
if (mDefaultTreatment == null) {
5255
throw new IllegalArgumentException("DefaultTreatment is null");
@@ -104,6 +107,10 @@ public Set<String> sets() {
104107
return mSets;
105108
}
106109

110+
public boolean trackImpression() {
111+
return mTrackImpressions;
112+
}
113+
107114
@Override
108115
public int hashCode() {
109116
int result = 17;
@@ -116,6 +123,7 @@ public int hashCode() {
116123
result = 31 * result + (int) (mChangeNumber ^ (mChangeNumber >>> 32));
117124
result = 31 * result + (mAlgo ^ (mAlgo >>> 32));
118125
result = 31 * result + ((mSets != null) ? mSets.hashCode() : 0);
126+
result = 31 * result + (mTrackImpressions ? 1 : 0);
119127
return result;
120128
}
121129

@@ -135,7 +143,8 @@ public boolean equals(Object obj) {
135143
&& mChangeNumber == other.mChangeNumber
136144
&& mAlgo == other.mAlgo
137145
&& (Objects.equals(mConfigurations, other.mConfigurations))
138-
&& (Objects.equals(mSets, other.mSets));
146+
&& (Objects.equals(mSets, other.mSets)
147+
&& mTrackImpressions == other.mTrackImpressions);
139148

140149
}
141150

@@ -146,7 +155,7 @@ public String toString() {
146155
", default treatment:" + mDefaultTreatment +
147156
", parsedConditions:" + mParsedCondition +
148157
", trafficTypeName:" + mTrafficTypeName + ", changeNumber:" + mChangeNumber +
149-
", algo:" + mAlgo + ", config:" + mConfigurations + ", sets:" + mSets;
158+
", algo:" + mAlgo + ", config:" + mConfigurations + ", sets:" + mSets + ", trackImpression:" + mTrackImpressions;
150159

151160
}
152161
}

src/main/java/io/split/android/engine/experiments/SplitParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ private ParsedSplit parseWithoutExceptionHandling(Split split, String matchingKe
124124
split.trafficAllocationSeed,
125125
split.algo,
126126
split.configurations,
127-
split.sets);
127+
split.sets,
128+
split.trackImpressions);
128129
}
129130

130131
private CombiningMatcher toMatcher(MatcherGroup matcherGroup, String matchingKey) throws UnsupportedMatcherException {
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package io.split.android.client.dtos;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
import io.split.android.client.utils.Json;
9+
10+
public class SplitDeserializationTest {
11+
12+
@Test
13+
public void trackImpressionsDefaultsToTrueWhenNotPresentInSplit() {
14+
assertTrue(Json.fromJson(getTestSplit(null), Split.class).trackImpressions);
15+
}
16+
17+
@Test
18+
public void trackImpressionsValueIsParsedCorrectly() {
19+
assertTrue(Json.fromJson(getTestSplit(true), Split.class).trackImpressions);
20+
assertFalse(Json.fromJson(getTestSplit(false), Split.class).trackImpressions);
21+
}
22+
23+
private String getTestSplit(Boolean trackImpressions) {
24+
return "{\n" +
25+
((trackImpressions != null) ? "\"trackImpressions\": " + trackImpressions + ",\n" : "") +
26+
" \"trafficTypeName\": \"client\",\n" +
27+
" \"name\": \"workm\",\n" +
28+
" \"trafficAllocation\": 100,\n" +
29+
" \"trafficAllocationSeed\": 147392224,\n" +
30+
" \"seed\": 524417105,\n" +
31+
" \"status\": \"ACTIVE\",\n" +
32+
" \"killed\": false,\n" +
33+
" \"defaultTreatment\": \"on\",\n" +
34+
" \"changeNumber\": 1602796638344,\n" +
35+
" \"algo\": 2,\n" +
36+
" \"configurations\": {},\n" +
37+
" \"conditions\": [\n" +
38+
" {\n" +
39+
" \"conditionType\": \"ROLLOUT\",\n" +
40+
" \"matcherGroup\": {\n" +
41+
" \"combiner\": \"AND\",\n" +
42+
" \"matchers\": [\n" +
43+
" {\n" +
44+
" \"keySelector\": {\n" +
45+
" \"trafficType\": \"client\",\n" +
46+
" \"attribute\": null\n" +
47+
" },\n" +
48+
" \"matcherType\": \"IN_SEGMENT\",\n" +
49+
" \"negate\": false,\n" +
50+
" \"userDefinedSegmentMatcherData\": {\n" +
51+
" \"segmentName\": \"new_segment\"\n" +
52+
" },\n" +
53+
" \"whitelistMatcherData\": null,\n" +
54+
" \"unaryNumericMatcherData\": null,\n" +
55+
" \"betweenMatcherData\": null,\n" +
56+
" \"booleanMatcherData\": null,\n" +
57+
" \"dependencyMatcherData\": null,\n" +
58+
" \"stringMatcherData\": null\n" +
59+
" }\n" +
60+
" ]\n" +
61+
" },\n" +
62+
" \"partitions\": [\n" +
63+
" {\n" +
64+
" \"treatment\": \"on\",\n" +
65+
" \"size\": 0\n" +
66+
" },\n" +
67+
" {\n" +
68+
" \"treatment\": \"off\",\n" +
69+
" \"size\": 0\n" +
70+
" },\n" +
71+
" {\n" +
72+
" \"treatment\": \"free\",\n" +
73+
" \"size\": 100\n" +
74+
" },\n" +
75+
" {\n" +
76+
" \"treatment\": \"conta\",\n" +
77+
" \"size\": 0\n" +
78+
" }\n" +
79+
" ],\n" +
80+
" \"label\": \"in segment new_segment\"\n" +
81+
" },\n" +
82+
" {\n" +
83+
" \"conditionType\": \"ROLLOUT\",\n" +
84+
" \"matcherGroup\": {\n" +
85+
" \"combiner\": \"AND\",\n" +
86+
" \"matchers\": [\n" +
87+
" {\n" +
88+
" \"keySelector\": {\n" +
89+
" \"trafficType\": \"client\",\n" +
90+
" \"attribute\": null\n" +
91+
" },\n" +
92+
" \"matcherType\": \"ALL_KEYS\",\n" +
93+
" \"negate\": false,\n" +
94+
" \"userDefinedSegmentMatcherData\": null,\n" +
95+
" \"whitelistMatcherData\": null,\n" +
96+
" \"unaryNumericMatcherData\": null,\n" +
97+
" \"betweenMatcherData\": null,\n" +
98+
" \"booleanMatcherData\": null,\n" +
99+
" \"dependencyMatcherData\": null,\n" +
100+
" \"stringMatcherData\": null\n" +
101+
" }\n" +
102+
" ]\n" +
103+
" },\n" +
104+
" \"partitions\": [\n" +
105+
" {\n" +
106+
" \"treatment\": \"on\",\n" +
107+
" \"size\": 100\n" +
108+
" },\n" +
109+
" {\n" +
110+
" \"treatment\": \"off\",\n" +
111+
" \"size\": 0\n" +
112+
" },\n" +
113+
" {\n" +
114+
" \"treatment\": \"free\",\n" +
115+
" \"size\": 0\n" +
116+
" },\n" +
117+
" {\n" +
118+
" \"treatment\": \"conta\",\n" +
119+
" \"size\": 0\n" +
120+
" }\n" +
121+
" ],\n" +
122+
" \"label\": \"default rule\"\n" +
123+
" }\n" +
124+
" ]\n" +
125+
" }";
126+
}
127+
}

src/test/java/io/split/android/engine/experiments/SplitParserTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import static org.hamcrest.Matchers.equalTo;
44
import static org.hamcrest.Matchers.is;
55
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertFalse;
67
import static org.junit.Assert.assertThat;
8+
import static org.junit.Assert.assertTrue;
79
import static org.mockito.Mockito.never;
810
import static org.mockito.Mockito.verify;
911
import static org.mockito.Mockito.when;
@@ -495,6 +497,22 @@ public void inLargeSegmentMatcherParsingTest() {
495497
verify(mMySegmentsStorageContainer, never()).getStorageForKey("matching_key");
496498
}
497499

500+
@Test
501+
public void trackImpressionsParsingTest(){
502+
SplitParser parser = createParser();
503+
504+
Split split = makeSplit("splitName", Collections.emptyList());
505+
split.trackImpressions = false;
506+
Split split2 = makeSplit("splitName", Collections.emptyList());
507+
split2.trackImpressions = true;
508+
509+
ParsedSplit actual = parser.parse(split);
510+
ParsedSplit actual2 = parser.parse(split2);
511+
512+
assertFalse(actual.trackImpression());
513+
assertTrue(actual2.trackImpression());
514+
}
515+
498516
private void set_matcher_test(Condition c, io.split.android.engine.matchers.Matcher m) {
499517

500518
SplitParser parser = createParser();
@@ -536,6 +554,7 @@ private Split makeSplit(String name, List<Condition> conditions, long changeNumb
536554
split.algo = 1;
537555
split.configurations = configurations;
538556
split.sets = Collections.emptySet();
557+
split.trackImpressions = true;
539558
return split;
540559
}
541560

src/test/java/io/split/android/helpers/SplitHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public static ParsedSplit createParsedSplit(
122122
seed,
123123
algo,
124124
configurations,
125-
Collections.emptySet()
125+
Collections.emptySet(),
126+
true
126127
);
127128
}
128129

0 commit comments

Comments
 (0)