Skip to content

Commit faedd48

Browse files
committed
polishing
1 parent 8d67468 commit faedd48

File tree

4 files changed

+34
-82
lines changed

4 files changed

+34
-82
lines changed

client/src/main/java/io/split/client/LegacyLocalhostSplitChangeFetcher.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.FileReader;
2020
import java.util.ArrayList;
2121
import java.util.HashMap;
22-
import java.util.List;
2322
import java.util.Optional;
2423

2524
public class LegacyLocalhostSplitChangeFetcher implements SplitChangeFetcher {

client/src/main/java/io/split/client/utils/LocalhostSanitizer.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private LocalhostSanitizer() {
3030
}
3131

3232
public static SplitChange sanitization(SplitChange splitChange) {
33-
splitChange = sanitizeTillAndSince(splitChange);
33+
sanitizeTillAndSince(splitChange);
3434
splitChange.featureFlags.d = sanitizeFeatureFlags(splitChange.featureFlags.d);
3535
splitChange.ruleBasedSegments.d = sanitizeRuleBasedSegments(splitChange.ruleBasedSegments.d);
3636

@@ -62,7 +62,6 @@ private static List<RuleBasedSegment> sanitizeRuleBasedSegments(List<RuleBasedSe
6262

6363
private static List<Split> sanitizeFeatureFlags(List<Split> featureFlags) {
6464
List<Split> splitsToRemove = new ArrayList<>();
65-
SecureRandom random = new SecureRandom();
6665
if (featureFlags != null) {
6766
for (Split split : featureFlags) {
6867
if (split.name == null) {
@@ -73,19 +72,10 @@ private static List<Split> sanitizeFeatureFlags(List<Split> featureFlags) {
7372
split.status = sanitizeStatus(split.status);
7473
split.defaultTreatment = sanitizeIfNullOrEmpty(split.defaultTreatment, LocalhostConstants.CONTROL);
7574
split.changeNumber = sanitizeChangeNumber(split.changeNumber, 0);
76-
77-
if (split.trafficAllocation == null || split.trafficAllocation < 0 || split.trafficAllocation > LocalhostConstants.SIZE_100) {
78-
split.trafficAllocation = LocalhostConstants.SIZE_100;
79-
}
80-
if (split.trafficAllocationSeed == null || split.trafficAllocationSeed == 0) {
81-
split.trafficAllocationSeed = -random.nextInt(10) * LocalhostConstants.MILLI_SECONDS;
82-
}
83-
if (split.seed == 0) {
84-
split.seed = -random.nextInt(10) * LocalhostConstants.MILLI_SECONDS;
85-
}
86-
if (split.algo != LocalhostConstants.ALGO) {
87-
split.algo = LocalhostConstants.ALGO;
88-
}
75+
split.trafficAllocation = sanitizeTrafficAllocation(split.trafficAllocation);
76+
split.trafficAllocationSeed = sanitizeSeed(split.trafficAllocationSeed);
77+
split.seed = sanitizeSeed(split.seed);
78+
split.algo = sanitizeAlgo(split.algo);
8979
split.conditions = sanitizeConditions((ArrayList<Condition>) split.conditions, false, split.trafficTypeName);
9080
}
9181
featureFlags.removeAll(splitsToRemove);
@@ -95,6 +85,28 @@ private static List<Split> sanitizeFeatureFlags(List<Split> featureFlags) {
9585
return featureFlags;
9686
}
9787

88+
private static int sanitizeSeed(Integer seed) {
89+
SecureRandom random = new SecureRandom();
90+
if (seed == null || seed == 0) {
91+
seed = -random.nextInt(10) * LocalhostConstants.MILLI_SECONDS;
92+
}
93+
return seed;
94+
}
95+
96+
private static int sanitizeAlgo(int algo) {
97+
if (algo != LocalhostConstants.ALGO) {
98+
algo = LocalhostConstants.ALGO;
99+
}
100+
return algo;
101+
}
102+
103+
private static int sanitizeTrafficAllocation(Integer trafficAllocation) {
104+
if (trafficAllocation == null || trafficAllocation < 0 || trafficAllocation > LocalhostConstants.SIZE_100) {
105+
trafficAllocation = LocalhostConstants.SIZE_100;
106+
}
107+
return trafficAllocation;
108+
}
109+
98110
private static ArrayList<Condition> sanitizeConditions(ArrayList<Condition> conditions, boolean createPartition, String trafficTypeName) {
99111
if (conditions == null) {
100112
conditions = new ArrayList<>();
@@ -114,18 +126,18 @@ private static ArrayList<Condition> sanitizeConditions(ArrayList<Condition> cond
114126
}
115127
return conditions;
116128
}
117-
private static String sanitizeIfNullOrEmpty(String toBeSantitized, String defaultValue) {
118-
if (toBeSantitized == null || toBeSantitized.isEmpty()) {
129+
private static String sanitizeIfNullOrEmpty(String toBeSanitized, String defaultValue) {
130+
if (toBeSanitized == null || toBeSanitized.isEmpty()) {
119131
return defaultValue;
120132
}
121-
return toBeSantitized;
133+
return toBeSanitized;
122134
}
123135

124-
private static long sanitizeChangeNumber(long toBeSantitized, long defaultValue) {
125-
if (toBeSantitized < 0) {
136+
private static long sanitizeChangeNumber(long toBeSanitized, long defaultValue) {
137+
if (toBeSanitized < 0) {
126138
return defaultValue;
127139
}
128-
return toBeSantitized;
140+
return toBeSanitized;
129141
}
130142

131143
private static Status sanitizeStatus(Status toBeSanitized) {

client/src/main/java/io/split/engine/sse/dtos/CommonChangeNotification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public String toString() {
8282
return String.format("Type: %s; Channel: %s; ChangeNumber: %s", getType(), getChannel(), getChangeNumber());
8383
}
8484

85-
private void updateDefinition(byte[] decodedBytes) throws UnsupportedEncodingException {
85+
private void updateDefinition(byte[] decodedBytes) {
8686
definition = (Y) Json.fromJson(new String(decodedBytes, StandardCharsets.UTF_8), _definitionClass);
8787
}
8888
}

client/src/main/java/io/split/storages/pluggable/adapters/UserCustomRuleBasedSegmentAdapterProducer.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)