Skip to content

Commit 11a247a

Browse files
authored
Merge branch 'Feature/Semver' into semver-less-equalto-matcher
2 parents 6fa6faf + 1204cce commit 11a247a

21 files changed

+836
-40
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.split;
2+
3+
public final class Spec {
4+
5+
private Spec() {
6+
// restrict instantiation
7+
}
8+
9+
public static final String SPEC_VERSION = "1.1";
10+
}
11+

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.split.client;
22

33
import com.google.common.annotations.VisibleForTesting;
4+
45
import io.split.client.dtos.SplitChange;
56
import io.split.client.dtos.SplitHttpResponse;
67
import io.split.client.exceptions.UriTooLongException;
@@ -21,6 +22,7 @@
2122
import java.net.URISyntaxException;
2223

2324
import static com.google.common.base.Preconditions.checkNotNull;
25+
import static io.split.Spec.SPEC_VERSION;
2426

2527
/**
2628
* Created by adilaijaz on 5/30/15.
@@ -31,6 +33,7 @@ public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
3133
private static final String SINCE = "since";
3234
private static final String TILL = "till";
3335
private static final String SETS = "sets";
36+
private static final String SPEC = "s";
3437
private final SplitHttpClient _client;
3538
private final URI _target;
3639
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;
@@ -58,13 +61,14 @@ public SplitChange fetch(long since, FetchOptions options) {
5861
long start = System.currentTimeMillis();
5962

6063
try {
61-
URIBuilder uriBuilder = new URIBuilder(_target).addParameter(SINCE, "" + since);
62-
if (options.hasCustomCN()) {
63-
uriBuilder.addParameter(TILL, "" + options.targetCN());
64-
}
64+
URIBuilder uriBuilder = new URIBuilder(_target).addParameter(SPEC, "" + SPEC_VERSION);
65+
uriBuilder.addParameter(SINCE, "" + since);
6566
if (!options.flagSetsFilter().isEmpty()) {
6667
uriBuilder.addParameter(SETS, "" + options.flagSetsFilter());
6768
}
69+
if (options.hasCustomCN()) {
70+
uriBuilder.addParameter(TILL, "" + options.targetCN());
71+
}
6872
URI uri = uriBuilder.build();
6973
SplitHttpResponse response = _client.get(uri, options, null);
7074

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.split.client.dtos;
2+
3+
/**
4+
* Metadata to support the between matcher.
5+
*
6+
* @author adil
7+
*/
8+
public class BetweenStringMatcherData {
9+
public String start;
10+
public String end;
11+
}

client/src/main/java/io/split/client/dtos/Matcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Matcher {
1313
public WhitelistMatcherData whitelistMatcherData;
1414
public UnaryNumericMatcherData unaryNumericMatcherData;
1515
public BetweenMatcherData betweenMatcherData;
16+
public BetweenStringMatcherData betweenStringMatcherData;
1617
public DependencyMatcherData dependencyMatcherData;
1718
public Boolean booleanMatcherData;
1819
public String stringMatcherData;

client/src/main/java/io/split/client/dtos/MatcherType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ public enum MatcherType {
3535
/* Semver matchers */
3636
EQUAL_TO_SEMVER,
3737
GREATER_THAN_OR_EQUAL_TO_SEMVER,
38-
LESS_THAN_OR_EQUAL_TO_SEMVER
38+
LESS_THAN_OR_EQUAL_TO_SEMVER,
39+
IN_LIST_SEMVER,
40+
BETWEEN_SEMVER
3941
}

client/src/main/java/io/split/engine/evaluator/Labels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public class Labels {
66
public static final String KILLED = "killed";
77
public static final String DEFINITION_NOT_FOUND = "definition not found";
88
public static final String EXCEPTION = "exception";
9-
public static final String UNSUPPORTED_MATCHER = "unsupported matcher type";
9+
public static final String UNSUPPORTED_MATCHER = "targeting rule type unsupported by sdk";
1010
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import io.split.engine.matchers.strings.WhitelistMatcher;
3232
import io.split.engine.matchers.GreaterThanOrEqualToSemverMatcher;
3333
import io.split.engine.matchers.LessThanOrEqualToSemverMatcher;
34+
import io.split.engine.matchers.InListSemverMatcher;
35+
import io.split.engine.matchers.BetweenSemverMatcher;
3436

3537
import org.slf4j.Logger;
3638
import org.slf4j.LoggerFactory;
@@ -198,17 +200,25 @@ private AttributeMatcher toMatcher(Matcher matcher) {
198200
delegate = new BooleanMatcher(matcher.booleanMatcherData);
199201
break;
200202
case EQUAL_TO_SEMVER:
201-
checkNotNull(matcher.stringMatcherData);
203+
checkNotNull(matcher.stringMatcherData, "stringMatcherData is required for EQUAL_TO_SEMVER matcher type");
202204
delegate = new EqualToSemverMatcher(matcher.stringMatcherData);
203205
break;
204206
case GREATER_THAN_OR_EQUAL_TO_SEMVER:
205-
checkNotNull(matcher.stringMatcherData);
207+
checkNotNull(matcher.stringMatcherData, "stringMatcherData is required for GREATER_THAN_OR_EQUAL_TO_SEMVER matcher type");
206208
delegate = new GreaterThanOrEqualToSemverMatcher(matcher.stringMatcherData);
207209
break;
208210
case LESS_THAN_OR_EQUAL_TO_SEMVER:
209-
checkNotNull(matcher.stringMatcherData);
211+
checkNotNull(matcher.stringMatcherData, "stringMatcherData is required for LESS_THAN_OR_EQUAL_SEMVER matcher type");
210212
delegate = new LessThanOrEqualToSemverMatcher(matcher.stringMatcherData);
211213
break;
214+
case IN_LIST_SEMVER:
215+
checkNotNull(matcher.whitelistMatcherData, "whitelistMatcherData is required for IN_LIST_SEMVER matcher type");
216+
delegate = new InListSemverMatcher(matcher.whitelistMatcherData.whitelist);
217+
break;
218+
case BETWEEN_SEMVER:
219+
checkNotNull(matcher.betweenStringMatcherData, "betweenStringMatcherData is required for BETWEEN_SEMVER matcher type");
220+
delegate = new BetweenSemverMatcher(matcher.betweenStringMatcherData.start, matcher.betweenStringMatcherData.end);
221+
break;
212222
default:
213223
throw new IllegalArgumentException("Unknown matcher type: " + matcher.matcherType);
214224
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.split.engine.matchers;
2+
3+
import io.split.engine.evaluator.EvaluationContext;
4+
5+
import java.util.Map;
6+
7+
public class BetweenSemverMatcher implements Matcher {
8+
9+
private final Semver _semverStart;
10+
private final Semver _semverEnd;
11+
12+
public BetweenSemverMatcher(String semverStart, String semverEnd) {
13+
_semverStart = Semver.build(semverStart);
14+
_semverEnd = Semver.build(semverEnd);
15+
}
16+
17+
@Override
18+
public boolean match(Object matchValue, String bucketingKey, Map<String, Object> attributes, EvaluationContext evaluationContext) {
19+
if (matchValue == null || _semverStart == null || _semverEnd == null) {
20+
return false;
21+
}
22+
Semver matchSemver = Semver.build(matchValue.toString());
23+
if (matchSemver == null) {
24+
return false;
25+
}
26+
27+
return matchSemver.Compare(_semverStart) >= 0 && matchSemver.Compare(_semverEnd) <= 0;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
StringBuilder bldr = new StringBuilder();
33+
bldr.append("between semver ");
34+
bldr.append(_semverStart.Version());
35+
bldr.append(" and ");
36+
bldr.append(_semverEnd.Version());
37+
return bldr.toString();
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
int result = 17;
43+
result = 31 * result + _semverStart.hashCode() + _semverEnd.hashCode();
44+
return result;
45+
}
46+
47+
@Override
48+
public boolean equals(Object obj) {
49+
if (obj == null) return false;
50+
if (this == obj) return true;
51+
if (!(obj instanceof BetweenSemverMatcher)) return false;
52+
53+
BetweenSemverMatcher other = (BetweenSemverMatcher) obj;
54+
55+
return _semverStart == other._semverStart && _semverEnd == other._semverEnd;
56+
}
57+
58+
}

client/src/main/java/io/split/engine/matchers/EqualToSemverMatcher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ public EqualToSemverMatcher(String semVer) {
1414

1515
@Override
1616
public boolean match(Object matchValue, String bucketingKey, Map<String, Object> attributes, EvaluationContext evaluationContext) {
17-
if (matchValue == null) {
17+
if (matchValue == null || _semVer == null) {
1818
return false;
1919
}
2020
Semver matchSemver = Semver.build(matchValue.toString());
2121
if (matchSemver == null) {
2222
return false;
2323
}
2424

25-
return _semVer != null && matchSemver.Version().equals(_semVer.Version());
25+
return matchSemver.Version().equals(_semVer.Version());
2626
}
2727

2828
@Override
2929
public String toString() {
3030
StringBuilder bldr = new StringBuilder();
31-
bldr.append("== ");
32-
bldr.append(_semVer);
31+
bldr.append("== semver ");
32+
bldr.append(_semVer.Version());
3333
return bldr.toString();
3434
}
3535

client/src/main/java/io/split/engine/matchers/GreaterThanOrEqualToSemverMatcher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ public GreaterThanOrEqualToSemverMatcher(String semVer) {
1414

1515
@Override
1616
public boolean match(Object matchValue, String bucketingKey, Map<String, Object> attributes, EvaluationContext evaluationContext) {
17-
if (matchValue == null) {
17+
if (matchValue == null || _semVer == null) {
1818
return false;
1919
}
2020
Semver matchSemver = Semver.build(matchValue.toString());
2121
if (matchSemver == null) {
2222
return false;
2323
}
2424

25-
return _semVer != null && matchSemver.Compare(_semVer) >= 0;
25+
return matchSemver.Compare(_semVer) >= 0;
2626
}
2727

2828
@Override
2929
public String toString() {
3030
StringBuilder bldr = new StringBuilder();
31-
bldr.append("== ");
32-
bldr.append(_semVer);
31+
bldr.append(">= semver ");
32+
bldr.append(_semVer.Version());
3333
return bldr.toString();
3434
}
3535

0 commit comments

Comments
 (0)