Skip to content

Commit 4468b2a

Browse files
author
Bilal Al
committed
added unsupported matcher flow
1 parent 8fa0c9c commit 4468b2a

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package io.split.engine.experiments;
22

33
import com.google.common.collect.Lists;
4-
import io.split.client.dtos.Condition;
5-
import io.split.client.dtos.Matcher;
6-
import io.split.client.dtos.MatcherGroup;
7-
import io.split.client.dtos.Partition;
8-
import io.split.client.dtos.Split;
4+
import io.split.client.dtos.*;
95
import io.split.engine.matchers.AllKeysMatcher;
106
import io.split.engine.matchers.AttributeMatcher;
117
import io.split.engine.matchers.BetweenMatcher;
@@ -59,6 +55,11 @@ private ParsedSplit parseWithoutExceptionHandling(Split split) {
5955

6056
for (Condition condition : split.conditions) {
6157
List<Partition> partitions = condition.partitions;
58+
if (checkUnsupportedMatcherExist(condition.matcherGroup.matchers)) {
59+
_log.error("Unsupported matcher type found for feature flag: " + split.name + " , will revert to default template matcher.");
60+
parsedConditionList.add(getTemplateCondition());
61+
break;
62+
}
6263
CombiningMatcher matcher = toMatcher(condition.matcherGroup);
6364
parsedConditionList.add(new ParsedCondition(condition.conditionType, matcher, partitions, condition.label));
6465
}
@@ -67,6 +68,31 @@ private ParsedSplit parseWithoutExceptionHandling(Split split) {
6768
split.changeNumber, split.trafficAllocation, split.trafficAllocationSeed, split.algo, split.configurations, split.sets);
6869
}
6970

71+
private boolean checkUnsupportedMatcherExist(List<io.split.client.dtos.Matcher> matchers) {
72+
for (io.split.client.dtos.Matcher matcher : matchers) {
73+
try {
74+
matcher.matcherType.equals(null);
75+
} catch (NullPointerException e) {
76+
// If the exception is caught, it means unsupported matcher
77+
return true;
78+
}
79+
}
80+
return false;
81+
}
82+
83+
private ParsedCondition getTemplateCondition() {
84+
List<Partition> templatePartitions = Lists.newArrayList();
85+
Partition partition = new Partition();
86+
partition.treatment = "control";
87+
partition.size = 100;
88+
templatePartitions.add(partition);
89+
return new ParsedCondition(
90+
ConditionType.ROLLOUT,
91+
CombiningMatcher.of(new AllKeysMatcher()),
92+
templatePartitions,
93+
"unsupported matcher type");
94+
}
95+
7096
private CombiningMatcher toMatcher(MatcherGroup matcherGroup) {
7197
List<io.split.client.dtos.Matcher> matchers = matcherGroup.matchers;
7298
checkArgument(!matchers.isEmpty());

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.split.engine.experiments;
22

33
import com.google.common.collect.Lists;
4+
import io.split.client.utils.Json;
45
import io.split.storages.SegmentCache;
56
import io.split.storages.memory.SegmentCacheInMemoryImpl;
67
import io.split.client.dtos.*;
@@ -39,6 +40,7 @@
3940
import static org.hamcrest.Matchers.equalTo;
4041
import static org.hamcrest.Matchers.is;
4142
import static org.junit.Assert.assertThat;
43+
import static org.junit.Assert.assertTrue;
4244

4345
/**
4446
* Tests for ExperimentParser
@@ -529,6 +531,27 @@ public void contains_string() {
529531
set_matcher_test(c, m);
530532
}
531533

534+
public void unsupportedMatcher() {
535+
SplitParser parser = new SplitParser();
536+
String splitWithUndefinedMatcher = "{\"since\":-1,\"till\": 1457726098069,\"splits\": [{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
537+
+ "\"trafficAllocation\": 100, \"trafficAllocationSeed\": 123456, \"seed\": 321654, \"status\": \"ACTIVE\","
538+
+ "\"killed\": false, \"defaultTreatment\": \"off\", \"algo\": 2,\"conditions\": [{ \"partitions\": ["
539+
+ "{\"treatment\": \"on\", \"size\": 50}, {\"treatment\": \"off\", \"size\": 50}], \"contitionType\": \"ROLLOUT\","
540+
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"UNKNOWN\", \"negate\": false}],"
541+
+ "\"combiner\": \"AND\"}}], \"sets\": [\"set1\"]}]}";
542+
SplitChange change = Json.fromJson(splitWithUndefinedMatcher, SplitChange.class);
543+
for (Split split : change.splits) {
544+
// should not cause exception
545+
ParsedSplit parsedSplit = parser.parse(split);
546+
for (ParsedCondition parsedCondition : parsedSplit.parsedConditions()) {
547+
for (AttributeMatcher matcher : parsedCondition.matcher().attributeMatchers()) {
548+
// Check the matcher is ALL_KEYS
549+
assertTrue(matcher.matcher().toString().equals(" in segment all"));
550+
}
551+
}
552+
}
553+
}
554+
532555
public void set_matcher_test(Condition c, io.split.engine.matchers.Matcher m) {
533556

534557
// SegmentSynchronizationTask segmentFetcher = new SegmentSynchronizationTaskImp(fetcherMap);

0 commit comments

Comments
 (0)