Skip to content

Commit 94ac3ed

Browse files
committed
removed spec_version global var
1 parent b86ac75 commit 94ac3ed

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ private Spec() {
99
// TODO: Change the schema to 1.3 when updating splitclient
1010
public static final String SPEC_1_3 = "1.3";
1111
public static final String SPEC_1_1 = "1.1";
12-
public static String SPEC_VERSION = SPEC_1_3;
1312
}
1413

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

+10-9
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,12 +87,12 @@ 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();
95-
return fetch(since, sinceRBS, options);
95+
return fetch(since, 0, options);
9696
}
9797

9898
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.SPLIT_SYNC, response.statusCode());
@@ -106,11 +106,12 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
106106
_telemetryRuntimeProducer.recordSyncLatency(HTTPLatenciesEnum.SPLITS, System.currentTimeMillis() - start);
107107
}
108108

109-
if (SPEC_VERSION.equals(Spec.SPEC_1_1)) {
109+
String body = response.body();
110+
if (specVersion.equals(Spec.SPEC_1_1)) {
110111
return Json.fromJson(body, SplitChangesOldPayloadDto.class).toSplitChange();
111112
}
112113

113-
return Json.fromJson(response.body(), SplitChange.class);
114+
return Json.fromJson(body, SplitChange.class);
114115
}
115116

116117
public Long getLastProxyCheckTimestamp() {
@@ -132,7 +133,7 @@ private ChangeDto<RuleBasedSegment> createEmptyDTO() {
132133
}
133134

134135
private URI buildURL(FetchOptions options, long since, long sinceRBS) throws URISyntaxException {
135-
URIBuilder uriBuilder = new URIBuilder(_target).addParameter(SPEC, "" + SPEC_VERSION);
136+
URIBuilder uriBuilder = new URIBuilder(_target).addParameter(SPEC, "" + specVersion);
136137
uriBuilder.addParameter(SINCE, "" + since);
137138
uriBuilder.addParameter(RB_SINCE, "" + sinceRBS);
138139
if (!options.flagSetsFilter().isEmpty()) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
225225
RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser();
226226
// SplitFetcher
227227
_splitFetcher = buildSplitFetcher(splitCache, splitParser, flagSetsFilter,
228-
ruleBasedSegmentParser, ruleBasedSegmentCache, config.isRootURIOverriden());
228+
ruleBasedSegmentParser, ruleBasedSegmentCache, config.isSdkEndpointOverridden());
229229

230230
// SplitSynchronizationTask
231231
_splitSynchronizationTask = new SplitSynchronizationTask(_splitFetcher,

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.annotations.SerializedName;
44

5+
import java.util.ArrayList;
56
import java.util.List;
67

78
public class SplitChangesOldPayloadDto {
@@ -25,8 +26,8 @@ public SplitChange toSplitChange() {
2526
rbs.t = -1;
2627
rbs.s = -1;
2728

28-
splitChange.ff = ff;
29-
splitChange.rbs = rbs;
29+
splitChange.featureFlags = ff;
30+
splitChange.ruleBasedSegments = rbs;
3031

3132
return splitChange;
3233
}

client/src/main/java/io/split/engine/sse/AuthApiClientImp.java

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

33
import com.google.gson.JsonObject;
4+
import io.split.Spec;
45
import io.split.client.dtos.SplitHttpResponse;
56
import io.split.client.utils.Json;
67
import io.split.engine.common.FetchOptions;
@@ -18,7 +19,6 @@
1819
import java.net.URI;
1920

2021
import static com.google.common.base.Preconditions.checkNotNull;
21-
import static io.split.Spec.SPEC_VERSION;
2222

2323
public class AuthApiClientImp implements AuthApiClient {
2424
private static final Logger _log = LoggerFactory.getLogger(AuthApiClientImp.class);
@@ -38,7 +38,7 @@ public AuthApiClientImp(String url, SplitHttpClient httpClient, TelemetryRuntime
3838
public AuthenticationResponse Authenticate() {
3939
try {
4040
long initTime = System.currentTimeMillis();
41-
URI uri = new URIBuilder(_target).addParameter(SPEC, "" + SPEC_VERSION).build();
41+
URI uri = new URIBuilder(_target).addParameter(SPEC, "" + Spec.SPEC_1_3).build();
4242
SplitHttpResponse response = _httpClient.get(uri, new FetchOptions.Builder().cacheControlHeaders(false).build(), null);
4343
Integer statusCode = response.statusCode();
4444

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

+4-4
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);
@@ -247,9 +246,12 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
247246
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(splitHtpClient, rootTarget,
248247
Mockito.mock(TelemetryRuntimeProducer.class), true);
249248

249+
Field specVersion = fetcher.getClass().getDeclaredField("specVersion");
250+
specVersion.setAccessible(true);
251+
specVersion.set(fetcher, Spec.SPEC_1_1);
252+
250253
SplitChange change = fetcher.fetch(-1, -1, new FetchOptions.Builder().cacheControlHeaders(true).build());
251254

252-
Assert.assertEquals(Spec.SPEC_1_1, Spec.SPEC_VERSION);
253255
List<ClassicHttpRequest> captured = requestCaptor.getAllValues();
254256
Assert.assertEquals(captured.size(), 2);
255257
Assert.assertTrue(captured.get(0).getUri().toString().contains("s=1.3"));
@@ -271,7 +273,6 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
271273
Thread.sleep(1000);
272274
change = fetcher.fetch(-1, -1, new FetchOptions.Builder().cacheControlHeaders(true).build());
273275

274-
Assert.assertEquals(Spec.SPEC_1_1, Spec.SPEC_VERSION);
275276
Assert.assertTrue(captured.get(2).getUri().toString().contains("s=1.3"));
276277
Assert.assertTrue(captured.get(3).getUri().toString().contains("s=1.1"));
277278
Assert.assertEquals(122, change.featureFlags.s);
@@ -283,7 +284,6 @@ public void testSwitchingToOldSpec() throws URISyntaxException, InvocationTarget
283284
// test if proxy is upgraded and spec 1.3 now works.
284285
Thread.sleep(1000);
285286
change = fetcher.fetch(-1, -1, new FetchOptions.Builder().cacheControlHeaders(true).build());
286-
Assert.assertEquals(Spec.SPEC_1_3, Spec.SPEC_VERSION);
287287
Assert.assertTrue(captured.get(4).getUri().toString().contains("s=1.3"));
288288
Assert.assertEquals(122, change.featureFlags.s);
289289
Assert.assertEquals(123, change.featureFlags.t);

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)