Skip to content

Commit 0a525ef

Browse files
Merge with development
1 parent 4dcbff8 commit 0a525ef

File tree

12 files changed

+63
-73
lines changed

12 files changed

+63
-73
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,12 @@ public SplitClientConfig build() {
852852
_streamingReconnectBackoffBase,
853853
_authServiceURL,
854854
_streamingServiceURL,
855+
_telemetryURl,
856+
_telemetryRefreshRate,
855857
_onDemandFetchRetryDelayMs,
856858
_onDemandFetchMaxRetries,
857859
_failedAttemptsBeforeLogging,
858-
_cdnDebugLogging,
859-
_telemetryURl,
860-
_telemetryRefreshRate);
860+
_cdnDebugLogging);
861861
}
862862
}
863863
}

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -145,36 +145,18 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
145145
_eventsRootTarget,
146146
config.eventsQueueSize(),
147147
config.eventFlushIntervalInMillis(),
148-
config.waitBeforeShutdown());
148+
config.waitBeforeShutdown(),
149+
_telemetryStorage);
149150

150151
_telemetrySyncTask = new TelemetrySyncTask(config.get_telemetryRefreshRate(), _telemetrySynchronizer);
151152

152-
// SyncManager
153-
_syncManager = SyncManagerImp.build(config.streamingEnabled(),
154-
_splitSynchronizationTask,
155-
_splitFetcher,
156-
_segmentSynchronizationTaskImp,
157-
_splitCache,
158-
config.authServiceURL(),
159-
_httpclient,
160-
config.streamingServiceURL(),
161-
config.authRetryBackoffBase(),
162-
buildSSEdHttpClient(config),
163-
_segmentCache,
164-
config.streamingRetryDelay(),
165-
config.streamingFetchMaxRetries(),
166-
config.failedAttemptsBeforeLogging(),
167-
config.cdnDebugLogging());
168-
_syncManager.start();
169-
170153
// Evaluator
171154
_evaluator = new EvaluatorImp(_splitCache);
172155

173156
// SplitClient
174157
_client = new SplitClientImpl(this,
175158
_splitCache,
176159
_impressionsManager,
177-
_cachedFireAndForgetMetrics,
178160
_eventClient,
179161
config,
180162
_gates,
@@ -186,9 +168,21 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
186168
_manager = new SplitManagerImpl(_splitCache, config, _gates, _telemetryStorage);
187169

188170
// SyncManager
189-
_syncManager = SyncManagerImp.build(config.streamingEnabled(), _splitSynchronizationTask, _splitFetcher, _segmentSynchronizationTaskImp, _splitCache,
190-
config.authServiceURL(), _httpclient, config.streamingServiceURL(), config.authRetryBackoffBase(), buildSSEdHttpClient(apiToken, config),
191-
_segmentCache, config.streamingRetryDelay(), _gates, _telemetryStorage, _telemetrySynchronizer,config);
171+
_syncManager = SyncManagerImp.build(config.streamingEnabled(),
172+
_splitSynchronizationTask,
173+
_splitFetcher,
174+
_segmentSynchronizationTaskImp,
175+
_splitCache,
176+
config.authServiceURL(),
177+
_httpclient,
178+
config.streamingServiceURL(),
179+
config.authRetryBackoffBase(),
180+
buildSSEdHttpClient(apiToken, config),
181+
_segmentCache,
182+
config.streamingRetryDelay(),
183+
config.streamingFetchMaxRetries(),
184+
config.failedAttemptsBeforeLogging(),
185+
config.cdnDebugLogging(), _gates, _telemetryStorage, _telemetrySynchronizer,config);
192186
_syncManager.start();
193187

194188
// DestroyOnShutDown

client/src/main/java/io/split/engine/common/SyncManagerImp.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,23 @@ public static SyncManagerImp build(boolean streamingEnabledConfig,
9696
SplitClientConfig config) {
9797
LinkedBlockingQueue<PushManager.Status> pushMessages = new LinkedBlockingQueue<>();
9898
Synchronizer synchronizer = new SynchronizerImp(splitSynchronizationTask,
99-
splitFetcher,
100-
segmentSynchronizationTaskImp,
101-
splitCache,
102-
segmentCache,
103-
streamingRetryDelay,
104-
maxOnDemandFetchRetries,
105-
failedAttemptsBeforeLogging,
106-
cdnDebugLogging,
107-
gates);
99+
splitFetcher,
100+
segmentSynchronizationTaskImp,
101+
splitCache,
102+
segmentCache,
103+
streamingRetryDelay,
104+
maxOnDemandFetchRetries,
105+
failedAttemptsBeforeLogging,
106+
cdnDebugLogging,
107+
gates);
108108

109109
PushManager pushManager = PushManagerImp.build(synchronizer,
110110
streamingServiceUrl,
111111
authUrl,
112112
httpClient,
113113
pushMessages,
114-
sseHttpClient);
114+
sseHttpClient,
115+
telemetryRuntimeProducer);
115116

116117
return new SyncManagerImp(streamingEnabledConfig,
117118
synchronizer,

client/src/main/java/io/split/engine/common/SynchronizerImp.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ public class SynchronizerImp implements Synchronizer {
3232
private final SplitSynchronizationTask _splitSynchronizationTask;
3333
private final SplitFetcher _splitFetcher;
3434
private final SegmentSynchronizationTask _segmentSynchronizationTaskImp;
35-
private final ScheduledExecutorService _syncAllScheduledExecutorService;
3635
private final SplitCache _splitCache;
3736
private final SegmentCache _segmentCache;
3837
private final int _onDemandFetchRetryDelayMs;
39-
private final SDKReadinessGates _gates;
4038
private final int _onDemandFetchMaxRetries;
4139
private final int _failedAttemptsBeforeLogging;
4240
private final boolean _cdnResponseHeadersLogging;
@@ -49,32 +47,25 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
4947
SplitCache splitCache,
5048
SegmentCache segmentCache,
5149
int onDemandFetchRetryDelayMs,
52-
SDKReadinessGates gates,
5350
int onDemandFetchMaxRetries,
5451
int failedAttemptsBeforeLogging,
55-
boolean cdnResponseHeadersLogging) {
52+
boolean cdnResponseHeadersLogging,
53+
SDKReadinessGates gates) {
5654
_splitSynchronizationTask = checkNotNull(splitSynchronizationTask);
5755
_splitFetcher = checkNotNull(splitFetcher);
5856
_segmentSynchronizationTaskImp = checkNotNull(segmentSynchronizationTaskImp);
5957
_splitCache = checkNotNull(splitCache);
6058
_segmentCache = checkNotNull(segmentCache);
6159
_onDemandFetchRetryDelayMs = checkNotNull(onDemandFetchRetryDelayMs);
62-
_gates = checkNotNull(gates);
63-
_onDemandFetchRetryDelayMs = onDemandFetchRetryDelayMs;
6460
_cdnResponseHeadersLogging = cdnResponseHeadersLogging;
6561
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
6662
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
6763

68-
ThreadFactory splitsThreadFactory = new ThreadFactoryBuilder()
69-
.setDaemon(true)
70-
.setNameFormat("Split-SyncAll-%d")
71-
.build();
72-
_syncAllScheduledExecutorService = Executors.newSingleThreadScheduledExecutor(splitsThreadFactory);
7364
}
7465

7566
@Override
7667
public boolean syncAll() {
77-
return _splitFetcher.fetchAll(true) && _segmentSynchronizationTaskImp.fetchAllSynchronous();
68+
return _splitFetcher.fetchAll(new FetchOptions.Builder().cacheControlHeaders(true).build()) && _segmentSynchronizationTaskImp.fetchAllSynchronous();
7869
}
7970

8071
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void runWithoutExceptionHandling(FetchOptions options) throws Interrupte
153153
}
154154
}
155155
@Override
156-
public void fetchAll(FetchOptions options) {
156+
public boolean fetchAll(FetchOptions options) {
157157
_log.debug("Fetch splits starting ...");
158158
long start = _splitCache.getChangeNumber();
159159
try {

client/src/main/java/io/split/engine/segments/SegmentFetcherImp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void callLoopRun(FetchOptions opts){
136136

137137
@Override
138138
public boolean runWhitCacheHeader(){
139-
this.fetchAndUpdate(new FetchOptions.Builder().cacheControlHeaders(true).build());
139+
return this.fetchAndUpdate(new FetchOptions.Builder().cacheControlHeaders(true).build());
140140
}
141141

142142
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void testFetcherWithCDNBypassOption() throws IOException, URISyntaxExcept
9797
when(httpClientMock.execute(requestCaptor.capture())).thenReturn(TestHelper.classicResponseToCloseableMock(response));
9898

9999
Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
100-
HttpSegmentChangeFetcher fetcher = HttpSegmentChangeFetcher.create(httpClientMock, rootTarget, metrics);
100+
HttpSegmentChangeFetcher fetcher = HttpSegmentChangeFetcher.create(httpClientMock, rootTarget, Mockito.mock(TelemetryStorage.class));
101101

102102
fetcher.fetch("someSegment", -1, new FetchOptions.Builder().targetChangeNumber(123).build());
103103
fetcher.fetch("someSegment2",-1, new FetchOptions.Builder().build());

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.split.engine.common.FetchOptions;
77
import io.split.engine.metrics.Metrics;
88
import io.split.telemetry.storage.InMemoryTelemetryStorage;
9+
import io.split.telemetry.storage.TelemetryRuntimeProducer;
910
import io.split.telemetry.storage.TelemetryStorage;
1011
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
1112
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@@ -108,8 +109,7 @@ public void testFetcherWithCDNBypassOption() throws IOException, URISyntaxExcept
108109
CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
109110
when(httpClientMock.execute(requestCaptor.capture())).thenReturn(TestHelper.classicResponseToCloseableMock(response));
110111

111-
Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
112-
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, metrics);
112+
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, Mockito.mock(TelemetryRuntimeProducer.class));
113113

114114
fetcher.fetch(-1, new FetchOptions.Builder().targetChangeNumber(123).build());
115115
fetcher.fetch(-1, new FetchOptions.Builder().build());
@@ -123,8 +123,7 @@ public void testFetcherWithCDNBypassOption() throws IOException, URISyntaxExcept
123123
public void testRandomNumberGeneration() throws URISyntaxException {
124124
URI rootTarget = URI.create("https://api.split.io");
125125
CloseableHttpClient httpClientMock = Mockito.mock(CloseableHttpClient.class);
126-
Metrics.NoopMetrics metrics = new Metrics.NoopMetrics();
127-
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, metrics);
126+
HttpSplitChangeFetcher fetcher = HttpSplitChangeFetcher.create(httpClientMock, rootTarget, Mockito.mock(TelemetryRuntimeProducer.class));
128127

129128
Set<Long> seen = new HashSet<>();
130129
long min = (long)Math.pow(2, 63) * (-1);

client/src/test/java/io/split/engine/common/SynchronizerTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ public void beforeMethod() {
3939
_segmentCache = Mockito.mock(SegmentCache.class);
4040
_gates = Mockito.mock(SDKReadinessGates.class);
4141

42-
_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache, 50, 10, 5, false);
42+
_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache, 50, 10, 5, false, _gates);
4343
}
4444

4545
@Test
4646
public void syncAll() throws InterruptedException {
47-
Mockito.when(_splitFetcher.fetchAll(true)).thenReturn(true);
47+
Mockito.when(_splitFetcher.fetchAll(Mockito.anyObject())).thenReturn(true);
4848
Mockito.when(_segmentFetcher.fetchAllSynchronous()).thenReturn(true);
4949
_synchronizer.syncAll();
5050

51-
Thread.sleep(100);
52-
Mockito.verify(_splitFetcher, Mockito.times(1)).fetchAll(new FetchOptions.Builder().cacheControlHeaders(true).build());
53-
Mockito.verify(_segmentFetcher, Mockito.times(1)).fetchAll(true);
51+
Thread.sleep(1000);
52+
Mockito.verify(_splitFetcher, Mockito.times(1)).fetchAll(Mockito.anyObject());
53+
Mockito.verify(_segmentFetcher, Mockito.times(1)).fetchAllSynchronous();
5454
}
5555

5656
@Test
@@ -99,7 +99,8 @@ public void testCDNBypassIsRequestedAfterNFailures() throws NoSuchFieldException
9999
50,
100100
3,
101101
1,
102-
true);
102+
true,
103+
Mockito.mock(SDKReadinessGates.class));
103104

104105
ArgumentCaptor<FetchOptions> optionsCaptor = ArgumentCaptor.forClass(FetchOptions.class);
105106
AtomicInteger calls = new AtomicInteger();
@@ -133,7 +134,8 @@ public void testCDNBypassRequestLimitAndBackoff() throws NoSuchFieldException, I
133134
50,
134135
3,
135136
1,
136-
true);
137+
true,
138+
Mockito.mock(SDKReadinessGates.class));
137139

138140
ArgumentCaptor<FetchOptions> optionsCaptor = ArgumentCaptor.forClass(FetchOptions.class);
139141
AtomicInteger calls = new AtomicInteger();
@@ -190,7 +192,8 @@ public void testCDNBypassRequestLimitAndForSegmentsBackoff() throws NoSuchFieldE
190192
50,
191193
3,
192194
1,
193-
true);
195+
true,
196+
Mockito.mock(SDKReadinessGates.class));
194197

195198
SegmentFetcher fetcher = Mockito.mock(SegmentFetcher.class);
196199
when(_segmentFetcher.getFetcher("someSegment")).thenReturn(fetcher);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.split.engine.segments.SegmentSynchronizationTaskImp;
1717
import io.split.grammar.Treatments;
1818
import io.split.telemetry.storage.InMemoryTelemetryStorage;
19+
import io.split.telemetry.storage.TelemetryRuntimeProducer;
1920
import io.split.telemetry.storage.TelemetryStorage;
2021
import org.junit.Assert;
2122
import org.junit.Test;
@@ -200,7 +201,7 @@ public void works_with_user_defined_segments() throws Exception {
200201
SegmentChangeFetcher segmentChangeFetcher = mock(SegmentChangeFetcher.class);
201202
SegmentChange segmentChange = getSegmentChange(0L, 0L, segmentName);
202203
when(segmentChangeFetcher.fetch(anyString(), anyLong(), any())).thenReturn(segmentChange);
203-
SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp(segmentChangeFetcher, 1,10, gates, segmentCache);
204+
SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp(segmentChangeFetcher, 1,10, gates, segmentCache, Mockito.mock(TelemetryStorage.class));
204205
segmentSynchronizationTask.startPeriodicFetching();
205206
SplitFetcherImp fetcher = new SplitFetcherImp(experimentChangeFetcher, new SplitParser(segmentSynchronizationTask, segmentCache), cache, TELEMETRY_STORAGE);
206207

@@ -225,7 +226,7 @@ public void testBypassCdnClearedAfterFirstHit() {
225226
SplitParser mockParser = new SplitParser(segmentSynchronizationTaskMock, segmentCacheMock);
226227
SDKReadinessGates mockGates = Mockito.mock(SDKReadinessGates.class);
227228
SplitCache mockCache = new InMemoryCacheImp();
228-
SplitFetcherImp fetcher = new SplitFetcherImp(mockFetcher, mockParser, mockGates, mockCache);
229+
SplitFetcherImp fetcher = new SplitFetcherImp(mockFetcher, mockParser, mockCache, Mockito.mock(TelemetryRuntimeProducer.class));
229230

230231

231232
SplitChange response1 = new SplitChange();

0 commit comments

Comments
 (0)