Skip to content

Commit 7b342fa

Browse files
authored
Allow re-scheduleSnapshotAutoUpdate (#363)
* Allow re-scheduleSnapshotAutoUpdate
1 parent a57d93a commit 7b342fa

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.github/workflows/staging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
required: true
1010
default: '17'
1111
os:
12-
description: 'Operating System (ubuntu-22.04, ubuntu-latest, windows-latest)'
12+
description: 'Operating System (ubuntu-latest, windows-latest)'
1313
required: true
1414
default: 'ubuntu-latest'
1515

src/main/java/com/switcherapi/client/SwitcherContextBase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ private static void scheduleSnapshotWatcher() {
292292
* @return ScheduledFuture instance
293293
*/
294294
public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue, SnapshotCallback callback) {
295-
if (StringUtils.isBlank(intervalValue) || scheduledExecutorService != null) {
295+
if (StringUtils.isBlank(intervalValue)) {
296296
return null;
297297
}
298298

299+
if (Objects.nonNull(scheduledExecutorService)) {
300+
terminateSnapshotAutoUpdateWorker();
301+
}
302+
299303
final long interval = SwitcherUtils.getMillis(intervalValue);
300304
final SnapshotCallback callbackFinal = Optional.ofNullable(callback).orElse(new SnapshotCallback() {});
301305
final Runnable runnableSnapshotValidate = () -> {

src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,15 @@ void shouldNotKillThread_whenAPI_wentLocal() {
219219

220220
@Test
221221
@Order(6)
222-
void shouldPreventSnapshotAutoUpdateToStart_whenAlreadySetup() {
223-
//given
222+
void shouldRestartSnapshotAutoUpdate_whenAlreadySetup() {
223+
//given - initialize (snapshot autoload)
224224
givenResponse(generateMockAuth(10)); //auth
225225
givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql
226226

227+
//given - snapshot auto update
228+
givenResponse(generateCheckSnapshotVersionResponse(Boolean.toString(false))); //criteria/snapshot_check
229+
givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql
230+
227231
//that
228232
Switchers.configure(ContextBuilder.builder(true)
229233
.context(Switchers.class.getCanonicalName())
@@ -235,8 +239,9 @@ void shouldPreventSnapshotAutoUpdateToStart_whenAlreadySetup() {
235239
.snapshotAutoUpdateInterval("1s"));
236240

237241
Switchers.initializeClient();
242+
238243
ScheduledFuture<?> snapshotUpdater = Switchers.scheduleSnapshotAutoUpdate("1m");
239-
assertNull(snapshotUpdater);
244+
assertNotNull(snapshotUpdater);
240245
}
241246

242247
}

0 commit comments

Comments
 (0)