diff --git a/pom.xml b/pom.xml index c9f7363..af03cb3 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ 2.48 2.48 1.2.0 - 2.13.2 + 2.14.0 3.20.0 @@ -65,9 +65,9 @@ 5.3.2 - 5.14.3 + 5.14.4 1.9.1 - 1.14.3 + 1.14.4 3.15.0 @@ -75,7 +75,7 @@ 3.12.0 3.5.5 3.2.8 - 5.5.0.6356 + 5.6.0.6792 0.8.14 0.10.0 diff --git a/src/main/java/com/switcherapi/client/model/AsyncSwitcher.java b/src/main/java/com/switcherapi/client/model/AsyncSwitcher.java index 2b4aaed..5febab0 100644 --- a/src/main/java/com/switcherapi/client/model/AsyncSwitcher.java +++ b/src/main/java/com/switcherapi/client/model/AsyncSwitcher.java @@ -47,7 +47,9 @@ public AsyncSwitcher(final Switcher switcher, long delay) { * Switcher result for the Switcher executions map. */ public void execute() { - SwitcherUtils.debug(logger, "nextRun: {} - currentTimeMillis: {}", nextRun, System.currentTimeMillis()); + if (logger.isDebugEnabled()) { + SwitcherUtils.debug(logger, "nextRun: {} - currentTimeMillis: {}", nextRun, System.currentTimeMillis()); + } if (nextRun < System.currentTimeMillis()) { SwitcherUtils.debug(logger, "Running AsyncSwitcher"); diff --git a/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdate2Test.java b/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdate2Test.java new file mode 100644 index 0000000..1ead8b4 --- /dev/null +++ b/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdate2Test.java @@ -0,0 +1,72 @@ +package com.switcherapi.client; + +import com.switcherapi.Switchers; +import com.switcherapi.fixture.CountDownHelper; +import com.switcherapi.fixture.MockWebServerHelper; +import mockwebserver3.QueueDispatcher; +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class SwitcherSnapshotAutoUpdate2Test extends MockWebServerHelper { + + private static final String SNAPSHOTS_LOCAL = Paths.get(StringUtils.EMPTY).toAbsolutePath() + "/src/test/resources/update"; + + @BeforeAll + static void setup() throws IOException { + setupMockServer(); + Switchers.loadProperties(); + } + + @AfterAll + static void tearDown() { + tearDownMockServer(); + SwitcherContextBase.terminateSnapshotAutoUpdateWorker(); + } + + @BeforeEach + void restoreStubs() { + ((QueueDispatcher) mockBackEnd.getDispatcher()).clear(); + SwitcherContextBase.terminateSnapshotAutoUpdateWorker(); + + CountDownHelper.wait(1); + } + + @Test + void shouldNotKillThread_whenAPI_wentLocal() { + //given + givenResponse(generateMockAuth(10)); //auth + givenResponse(generateSnapshotResponse("default_outdated.json", SNAPSHOTS_LOCAL)); //graphql + + //that + Switchers.configure(ContextBuilder.builder(true) + .context(Switchers.class.getName()) + .url(String.format("http://localhost:%s", mockBackEnd.getPort())) + .apiKey("[API_KEY]") + .environment("generated_mock_default_6") + .local(true) + .snapshotAutoLoad(true) + .snapshotAutoUpdateInterval("1s")); + + Switchers.initializeClient(); + assertEquals(1, Switchers.getSnapshotVersion()); + + CountDownHelper.wait(1); + + //given - API is remote again + givenResponse(generateCheckSnapshotVersionResponse(Boolean.toString(false))); //criteria/snapshot_check + givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql + + //test + CountDownHelper.wait(2); + assertEquals(2, Switchers.getSnapshotVersion()); + } + +} diff --git a/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java b/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java index c8a5f6f..daab30d 100644 --- a/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java +++ b/src/test/java/com/switcherapi/client/SwitcherSnapshotAutoUpdateTest.java @@ -185,37 +185,6 @@ void shouldUpdateSnapshot_remote_inMemory() { @Test @Order(5) - void shouldNotKillThread_whenAPI_wentLocal() { - //given - givenResponse(generateMockAuth(10)); //auth - givenResponse(generateSnapshotResponse("default_outdated.json", SNAPSHOTS_LOCAL)); //graphql - - //that - Switchers.configure(ContextBuilder.builder(true) - .context(Switchers.class.getName()) - .url(String.format("http://localhost:%s", mockBackEnd.getPort())) - .apiKey("[API_KEY]") - .environment("generated_mock_default_6") - .local(true) - .snapshotAutoLoad(true) - .snapshotAutoUpdateInterval("1s")); - - Switchers.initializeClient(); - assertEquals(1, Switchers.getSnapshotVersion()); - - CountDownHelper.wait(1); - - //given - API is remote again - givenResponse(generateCheckSnapshotVersionResponse(Boolean.toString(false))); //criteria/snapshot_check - givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql - - //test - CountDownHelper.wait(2); - assertEquals(2, Switchers.getSnapshotVersion()); - } - - @Test - @Order(6) void shouldRestartSnapshotAutoUpdate_whenAlreadySetup() { //given - initialize (snapshot autoload) givenResponse(generateMockAuth(10)); //auth diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties new file mode 100644 index 0000000..3666514 --- /dev/null +++ b/src/test/resources/simplelogger.properties @@ -0,0 +1,17 @@ +# SLF4J SimpleLogger configuration +# https://www.slf4j.org/api/org/slf4j/simple/SimpleLogger.html + +# Default log level for all loggers +org.slf4j.simpleLogger.defaultLogLevel=info + +# DEBUG for the playground and the client library +org.slf4j.simpleLogger.log.com.switcherapi.playground=debug +org.slf4j.simpleLogger.log.com.switcherapi.client=debug + +# Date/time format +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS + +# Show the logger name (abbreviated) +org.slf4j.simpleLogger.showShortLogName=true +