Skip to content

Commit 00402eb

Browse files
committed
resolve conflicts
1 parent 0c9e297 commit 00402eb

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.ArrayList;
2929

3030
import static com.google.common.base.Preconditions.checkNotNull;
31-
import static io.split.Spec.SPEC_VERSION;
3231
import static io.split.Spec.SPEC_1_3;
3332
import static io.split.Spec.SPEC_1_1;
3433

@@ -44,6 +43,7 @@ public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
4443
private static final String TILL = "till";
4544
private static final String SETS = "sets";
4645
private static final String SPEC = "s";
46+
private String specVersion = SPEC_1_3;
4747
private int PROXY_CHECK_INTERVAL_MILLISECONDS_SS = 24 * 60 * 60 * 1000;
4848
private Long _lastProxyCheckTimestamp = 0L;
4949
private final SplitHttpClient _client;
@@ -75,9 +75,9 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
7575
long start = System.currentTimeMillis();
7676
SplitHttpResponse response;
7777
try {
78-
if (SPEC_VERSION.equals(SPEC_1_1) && (System.currentTimeMillis() - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS)) {
78+
if (specVersion.equals(SPEC_1_1) && (System.currentTimeMillis() - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS)) {
7979
_log.info("Switching to new Feature flag spec ({}) and fetching.", SPEC_1_3);
80-
SPEC_VERSION = SPEC_1_3;
80+
specVersion = SPEC_1_3;
8181
}
8282
URI uri = buildURL(options, since, sinceRBS);
8383
response = _client.get(uri, options, null);
@@ -87,8 +87,8 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
8787
throw new UriTooLongException(String.format("Status code: %s. Message: %s", response.statusCode(), response.statusMessage()));
8888
}
8989

90-
if (response.statusCode() == HttpStatus.SC_BAD_REQUEST && SPEC_VERSION.equals(Spec.SPEC_1_3) && _rootURIOverriden) {
91-
SPEC_VERSION = Spec.SPEC_1_1;
90+
if (response.statusCode() == HttpStatus.SC_BAD_REQUEST && specVersion.equals(Spec.SPEC_1_3) && _rootURIOverriden) {
91+
specVersion = Spec.SPEC_1_1;
9292
_log.warn("Detected proxy without support for Feature flags spec {} version, will switch to spec version {}",
9393
SPEC_1_3, SPEC_1_1);
9494
_lastProxyCheckTimestamp = System.currentTimeMillis();
@@ -107,7 +107,7 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
107107
}
108108

109109
SplitChange splitChange = new SplitChange();
110-
if (SPEC_VERSION.equals(Spec.SPEC_1_1)) {
110+
if (specVersion.equals(Spec.SPEC_1_1)) {
111111
splitChange.featureFlags = convertBodyToOldSpec(response.body());
112112
splitChange.ruleBasedSegments = createEmptyDTO();
113113
} else {
@@ -134,11 +134,11 @@ private ChangeDto<RuleBasedSegment> createEmptyDTO() {
134134
return dto;
135135
}
136136
private ChangeDto<Split> convertBodyToOldSpec(String body) {
137-
return Json.fromJson(body, SplitChangesOldPayloadDto.class).toChangeDTO();
137+
return Json.fromJson(body, SplitChangesOldPayloadDto.class).toSplitChange().featureFlags;
138138
}
139139

140140
private URI buildURL(FetchOptions options, long since, long sinceRBS) throws URISyntaxException {
141-
URIBuilder uriBuilder = new URIBuilder(_target).addParameter(SPEC, "" + SPEC_VERSION);
141+
URIBuilder uriBuilder = new URIBuilder(_target).addParameter(SPEC, "" + specVersion);
142142
uriBuilder.addParameter(SINCE, "" + since);
143143
uriBuilder.addParameter(RB_SINCE, "" + sinceRBS);
144144
if (!options.flagSetsFilter().isEmpty()) {

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

+12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.split.client;
22

3+
import com.google.gson.JsonObject;
34
import com.google.gson.stream.JsonReader;
45
import io.split.client.dtos.ChangeDto;
56
import io.split.client.dtos.SplitChange;
7+
import io.split.client.dtos.SplitChangesOldPayloadDto;
68
import io.split.client.utils.InputStreamProvider;
79
import io.split.client.utils.Json;
810
import io.split.client.utils.LocalhostSanitizer;
@@ -37,13 +39,23 @@ public JsonLocalhostSplitChangeFetcher(InputStreamProvider inputStreamProvider)
3739
public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
3840
try {
3941
JsonReader jsonReader = new JsonReader(new BufferedReader(new InputStreamReader(_inputStreamProvider.get(), StandardCharsets.UTF_8)));
42+
if (checkOldSpec(new JsonReader(new BufferedReader(new InputStreamReader(_inputStreamProvider.get(), StandardCharsets.UTF_8))))) {
43+
SplitChange splitChange = new SplitChange();
44+
splitChange.featureFlags = Json.fromJson(jsonReader, SplitChangesOldPayloadDto.class).toSplitChange().featureFlags;
45+
splitChange.ruleBasedSegments = ChangeDto.createEmptyDto();
46+
return splitChange;
47+
}
4048
SplitChange splitChange = Json.fromJson(jsonReader, SplitChange.class);
4149
return processSplitChange(splitChange, since, sinceRBS);
4250
} catch (Exception e) {
4351
throw new IllegalStateException("Problem fetching splitChanges: " + e.getMessage(), e);
4452
}
4553
}
4654

55+
private boolean checkOldSpec(JsonReader jsonReader) {
56+
return Json.fromJson(jsonReader, JsonObject.class).has("splits");
57+
}
58+
4759
private SplitChange processSplitChange(SplitChange splitChange, long changeNumber, long changeNumberRBS) throws NoSuchAlgorithmException {
4860
SplitChange splitChangeToProcess = LocalhostSanitizer.sanitization(splitChange);
4961
// if the till is less than storage CN and different from the default till ignore the change

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ public CustomHeaderDecorator customHeaderDecorator() {
412412
return _customHeaderDecorator;
413413
}
414414

415-
public boolean isRootURIOverriden() {
416-
return _endpoint == SDK_ENDPOINT;
415+
public boolean isSdkEndpointOverridden() {
416+
return !_endpoint.equals(SDK_ENDPOINT);
417417
}
418418

419419
public CustomHttpModule alternativeHTTPModule() { return _alternativeHTTPModule; }

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

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.split.engine.experiments;
22

33
import io.split.client.dtos.ChangeDto;
4-
import io.split.client.dtos.RuleBasedSegment;
5-
import io.split.client.dtos.Split;
64
import io.split.client.dtos.SplitChange;
75
import io.split.client.exceptions.UriTooLongException;
86
import io.split.client.interceptors.FlagSetsFilter;

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

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public void update(List<ParsedRuleBasedSegment> toAdd, List<String> toRemove, lo
5454
//NoOp
5555
}
5656

57-
@Override
5857
public Set<String> getSegments() {
5958
//NoOp
6059
return new HashSet<>();

client/src/test/java/io/split/client/HttpSplitChangeFetcherTest.java

-5
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ public void testURLTooLong() throws IOException, URISyntaxException, IllegalAcce
198198
@Test
199199
public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTargetException,
200200
NoSuchMethodException, IllegalAccessException, IOException, NoSuchFieldException, InterruptedException {
201-
Spec.SPEC_VERSION = Spec.SPEC_1_3;
202201
URI rootTarget = URI.create("https://api.split.io");
203202
CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
204203
HttpEntity entityMock = Mockito.mock(HttpEntity.class);
@@ -249,7 +248,6 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
249248

250249
SplitChange change = fetcher.fetch(-1, -1, new FetchOptions.Builder().cacheControlHeaders(true).build());
251250

252-
Assert.assertEquals(Spec.SPEC_1_1, Spec.SPEC_VERSION);
253251
List<ClassicHttpRequest> captured = requestCaptor.getAllValues();
254252
Assert.assertEquals(captured.size(), 2);
255253
Assert.assertTrue(captured.get(0).getUri().toString().contains("s=1.3"));
@@ -262,7 +260,6 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
262260
Assert.assertEquals(0, change.ruleBasedSegments.d.size());
263261
Assert.assertEquals(-1, change.ruleBasedSegments.s);
264262
Assert.assertEquals(-1, change.ruleBasedSegments.t);
265-
Assert.assertTrue(fetcher.getLastProxyCheckTimestamp() > 0);
266263

267264
// Set proxy interval to low number to force check for spec 1.3
268265
Field proxyInterval = fetcher.getClass().getDeclaredField("PROXY_CHECK_INTERVAL_MILLISECONDS_SS");
@@ -271,7 +268,6 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
271268
Thread.sleep(1000);
272269
change = fetcher.fetch(-1, -1, new FetchOptions.Builder().cacheControlHeaders(true).build());
273270

274-
Assert.assertEquals(Spec.SPEC_1_1, Spec.SPEC_VERSION);
275271
Assert.assertTrue(captured.get(2).getUri().toString().contains("s=1.3"));
276272
Assert.assertTrue(captured.get(3).getUri().toString().contains("s=1.1"));
277273
Assert.assertEquals(122, change.featureFlags.s);
@@ -283,7 +279,6 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
283279
// test if proxy is upgraded and spec 1.3 now works.
284280
Thread.sleep(1000);
285281
change = fetcher.fetch(-1, -1, new FetchOptions.Builder().cacheControlHeaders(true).build());
286-
Assert.assertEquals(Spec.SPEC_1_3, Spec.SPEC_VERSION);
287282
Assert.assertTrue(captured.get(4).getUri().toString().contains("s=1.3"));
288283
Assert.assertEquals(122, change.featureFlags.s);
289284
Assert.assertEquals(123, change.featureFlags.t);

client/src/test/java/io/split/client/utils/CustomDispatcher.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public static CustomDispatcher.Builder builder() {
3737
return new CustomDispatcher.Builder();
3838
}
3939

40-
public String bodySince1585948850109 = "{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}, \"rbs\":{\"s\":1585948850109,\"t\":1585948850110,\"d\":[]}}";
41-
4240
@NotNull
4341
@Override
4442
public MockResponse dispatch(@NotNull RecordedRequest request) {
@@ -52,7 +50,7 @@ public MockResponse dispatch(@NotNull RecordedRequest request) {
5250
case CustomDispatcher.AUTH_DISABLED:
5351
return getResponse(CustomDispatcher.AUTH_DISABLED,new MockResponse().setBody(inputStreamToString("streaming-auth-push-disabled.json")));
5452
case CustomDispatcher.SINCE_1585948850109:
55-
return getResponse(CustomDispatcher.SINCE_1585948850109, new MockResponse().setBody(bodySince1585948850109));
53+
return getResponse(CustomDispatcher.SINCE_1585948850109, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}, \"rbs\":{\"s\":1585948850109,\"t\":1585948850110,\"d\":[]}}"));
5654
case SINCE_1585948850109_FLAG_SET:
5755
return getResponse(SINCE_1585948850109_FLAG_SET, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}, \"rbs\":{\"s\":1585948850109,\"t\":1585948850110,\"d\":[]}}"));
5856
case CustomDispatcher.SINCE_1585948850110:

client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public void testLocalhostSegmentChangeFetcher() throws InterruptedException, Fil
171171
ruleBasedSegmentParser, ruleBasedSegmentCacheProducer);
172172

173173
SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcher, splitCacheProducer, 1000, null);
174-
Spec.SPEC_VERSION = Spec.SPEC_1_1; // check old spec
175174

176175
splitSynchronizationTask.start();
177176

0 commit comments

Comments
 (0)