From b6546cd73dea747f6a2a74e89c185ee842b69a1a Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:05:31 -0700
Subject: [PATCH 1/7] Fixes and improves AsyncSwitcher
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c791e57c..659e16e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
com.github.switcherapi
switcher-client
jar
- 2.0.6
+ 2.0.7-SNAPSHOT
Switcher Client
Switcher Client SDK for working with Switcher API
From 908a52c5a1edd048b7bbbcca9efa03079a007bf7 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:14:39 -0700
Subject: [PATCH 2/7] Skipped failling test at SwitcherBasicTest
---
.../com/github/switcherapi/client/SwitcherBasicTest.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java b/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java
index 4848dc3f..a370360c 100644
--- a/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java
+++ b/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java
@@ -4,10 +4,7 @@
import com.github.switcherapi.client.model.Switcher;
import com.github.switcherapi.fixture.MockWebServerHelper;
import mockwebserver3.QueueDispatcher;
-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 org.junit.jupiter.api.*;
import java.io.IOException;
@@ -48,6 +45,7 @@ void resetSwitcherContextState() {
}
@Test
+ @Disabled("This test is disabled because it start failing when using the new GitHub runners (Version: 20240414.1.0 - 2.0.361.1)")
void shouldReturnTrue() {
//auth
givenAuthResponse();
From b7409368476f05d1880d25567eda63014e593548 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:19:08 -0700
Subject: [PATCH 3/7] Test on java17 ubuntu only
---
.github/workflows/master-2.yml | 4 ++--
.../com/github/switcherapi/client/SwitcherBasicTest.java | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml
index d173e78f..4c57be68 100644
--- a/.github/workflows/master-2.yml
+++ b/.github/workflows/master-2.yml
@@ -34,8 +34,8 @@ jobs:
strategy:
fail-fast: false
matrix:
- java: [ '11', '17', '18', '21']
- os: [ ubuntu-latest, windows-latest ]
+ java: [ '17' ]
+ os: [ ubuntu-latest, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
diff --git a/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java b/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java
index a370360c..4848dc3f 100644
--- a/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java
+++ b/src/test/java/com/github/switcherapi/client/SwitcherBasicTest.java
@@ -4,7 +4,10 @@
import com.github.switcherapi.client.model.Switcher;
import com.github.switcherapi.fixture.MockWebServerHelper;
import mockwebserver3.QueueDispatcher;
-import org.junit.jupiter.api.*;
+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;
@@ -45,7 +48,6 @@ void resetSwitcherContextState() {
}
@Test
- @Disabled("This test is disabled because it start failing when using the new GitHub runners (Version: 20240414.1.0 - 2.0.361.1)")
void shouldReturnTrue() {
//auth
givenAuthResponse();
From 4bedcfc1d5a36b86cdb48426890f39976e9d65a2 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:25:04 -0700
Subject: [PATCH 4/7] Replaced ununtu-latest by ubuntu-20.04
---
.github/workflows/master-2.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/master-2.yml b/.github/workflows/master-2.yml
index 4c57be68..1f212e12 100644
--- a/.github/workflows/master-2.yml
+++ b/.github/workflows/master-2.yml
@@ -9,7 +9,7 @@ on:
jobs:
build-scan:
name: SonarCloud Scan
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
steps:
@@ -34,8 +34,8 @@ jobs:
strategy:
fail-fast: false
matrix:
- java: [ '17' ]
- os: [ ubuntu-latest, ubuntu-20.04 ]
+ java: [ '11', '17', '18', '21']
+ os: [ ubuntu-20.04, windows-latest ]
runs-on: ${{ matrix.os }}
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
From 483f2bdc23d836071244b24d85ad6af3860b7f46 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:42:24 -0700
Subject: [PATCH 5/7] Added staging Action for isolation test
---
.github/workflows/master.yml | 4 +--
.github/workflows/staging.yml | 47 +++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
create mode 100644 .github/workflows/staging.yml
diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml
index 8051f1fd..ccca5724 100644
--- a/.github/workflows/master.yml
+++ b/.github/workflows/master.yml
@@ -9,7 +9,7 @@ on:
jobs:
build-scan:
name: SonarCloud Scan
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
steps:
@@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
java: [ '8', '11', '17', '18', '21']
- os: [ ubuntu-latest, windows-latest ]
+ os: [ ubuntu-20.04, windows-latest ]
runs-on: ${{ matrix.os }}
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml
new file mode 100644
index 00000000..02c74011
--- /dev/null
+++ b/.github/workflows/staging.yml
@@ -0,0 +1,47 @@
+name: Staging CI
+run-name: Staging - Java ${{ github.event.inputs.jdk }} / ${{ github.event.inputs.os }} by @${{ github.actor }}
+
+on:
+ workflow_dispatch:
+ inputs:
+ jdk:
+ description: 'JDK version'
+ required: true
+ default: '17'
+ os:
+ description: 'Operating System (ubuntu-20.04, ubuntu-latest, windows-latest)'
+ required: true
+ default: 'ubuntu-latest'
+
+jobs:
+ build-test:
+ name: Build & Test - JDK ${{ github.event.inputs.jdk }} on ${{ github.event.inputs.os }}
+
+ runs-on:
+ os: ${{ github.event.inputs.os }}
+ java: ${{ github.event.inputs.jdk }}
+
+ steps:
+ - name: Git checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Setup Java
+ uses: actions/setup-java@v4
+ with:
+ distribution: 'temurin'
+ java-version: ${{ github.event.inputs.jdk }}
+
+ - name: Show Versions
+ run: mvn -version
+
+ - name: Cache Maven packages
+ uses: actions/cache@v4
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-m2
+ restore-keys: ${{ runner.os }}-m2
+
+ - name: Build/Test
+ run: mvn -B clean package
\ No newline at end of file
From 1f737a318b0b274811920f0d9fad8dd4ba7ee34b Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:47:07 -0700
Subject: [PATCH 6/7] Adding the actual fix
---
.../switcherapi/client/model/AsyncSwitcher.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java b/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java
index e1790b29..b5dbff54 100644
--- a/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java
+++ b/src/main/java/com/github/switcherapi/client/model/AsyncSwitcher.java
@@ -6,6 +6,9 @@
import com.github.switcherapi.client.exception.SwitcherException;
import com.github.switcherapi.client.model.response.CriteriaResponse;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
/**
* Implementation handle asynchronous Criteria execution when using throttle.
*
Threads are only created when the time calculated for the next run is lower than the current time.
@@ -18,10 +21,16 @@ public class AsyncSwitcher implements Runnable {
private static final Logger logger = LogManager.getLogger(AsyncSwitcher.class);
+ private final ExecutorService executorService;
+
private Switcher switcher;
private long nextRun = 0;
+ public AsyncSwitcher() {
+ this.executorService = Executors.newCachedThreadPool();
+ }
+
/**
* Validate if next run is ready to be performed, otherwise it will skip and delegate the
* Switcher result for the Switcher history execution.
@@ -36,7 +45,7 @@ public synchronized void execute(final Switcher switcher) {
logger.debug("Running AsyncSwitcher");
this.nextRun = System.currentTimeMillis() + switcher.delay;
- new Thread(this, AsyncSwitcher.class.getName()).start();
+ this.executorService.submit(this);
}
}
@@ -44,6 +53,9 @@ public synchronized void execute(final Switcher switcher) {
public void run() {
try {
final CriteriaResponse response = switcher.getContext().executeCriteria(this.switcher);
+ switcher.getHistoryExecution().removeIf(item ->
+ this.switcher.getSwitcherKey().equals(item.getSwitcherKey()) &&
+ this.switcher.getEntry().equals(item.getEntry()));
switcher.getHistoryExecution().add(response);
} catch (SwitcherException e) {
logger.error(e);
From 3addd88e20080e3ca073be2755a8cc2dabcfe170 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Sun, 21 Apr 2024 14:54:39 -0700
Subject: [PATCH 7/7] Refactored pom - bump deps and plugin versions
---
pom.xml | 50 ++++++++++---------
.../playground/ClientPlayground.java | 4 +-
2 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/pom.xml b/pom.xml
index 659e16e6..0931846f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,38 +51,40 @@
${java.version}
- 3.1.5
- 3.1.5
- 3.1.5
+ 3.1.6
+ 3.1.6
+ 3.1.6
2.10.1
3.14.0
3.10.0
- 2.23.0
+ 2.23.1
- 5.0.0-alpha.12
+ 5.0.0-alpha.14
5.10.2
2.2.0
- 3.12.1
- 3.3.0
- 3.2.5
- 3.1.0
- 3.10.0.2594
- 0.8.11
+ 3.13.0
+ 3.3.1
+ 3.6.3
+ 3.2.5
+ 3.4.1
+ 3.2.4
+ 3.11.0.3922
+ 0.8.12
jacoco
reuseReports
java
- **/model/**/*.java,
- **/exception/**/*.java,
- **/service/validators/RegexValidatorV8.java
-
+ **/model/**/*.java,
+ **/exception/**/*.java,
+ **/service/validators/RegexValidatorV8.java
+
@@ -102,7 +104,7 @@
jersey-media-json-jackson
${jersey-media-json-jackson.version}
-
+
com.google.code.gson
gson
@@ -242,7 +244,7 @@
org.sonarsource.scanner.maven
sonar-maven-plugin
- ${sonar.version}
+ ${sonar-maven-plugin.version}
verify
@@ -263,7 +265,7 @@
org.apache.maven.plugins
maven-source-plugin
- ${maven-source.version}
+ ${maven-source-plugin.version}
attach-sources
@@ -276,7 +278,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- ${maven-source.version}
+ ${maven-javadoc-plugin.version}
attach-javadocs
@@ -289,7 +291,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- ${maven-gpg.version}
+ ${maven-gpg-plugin.version}
sign-artifacts
@@ -311,7 +313,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- ${maven-compiler.version}
+ ${maven-compiler-plugin.version}
org.sonarsource.scanner.maven
@@ -321,7 +323,7 @@
org.jacoco
jacoco-maven-plugin
- ${jacoco.version}
+ ${jacoco-maven-plugin.version}
@@ -339,7 +341,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- ${maven-surefire.version}
+ ${maven-surefire-plugin.version}
--add-opens java.base/java.util=ALL-UNNAMED
@@ -352,7 +354,7 @@
org.apache.maven.plugins
maven-jar-plugin
- ${maven-source.version}
+ ${maven-jar-plugin.version}
**/log4j2.properties
diff --git a/src/test/java/com/github/switcherapi/playground/ClientPlayground.java b/src/test/java/com/github/switcherapi/playground/ClientPlayground.java
index b02a64f2..d5f738dd 100644
--- a/src/test/java/com/github/switcherapi/playground/ClientPlayground.java
+++ b/src/test/java/com/github/switcherapi/playground/ClientPlayground.java
@@ -32,8 +32,8 @@ public static void test() {
scheduler.scheduleAtFixedRate(() -> {
long time = System.currentTimeMillis();
- logger.info("Switcher is on: " + switcher.isItOn());
- logger.info("Time elapsed: " + (System.currentTimeMillis() - time));
+ logger.info("Switcher is on: {}", switcher.isItOn());
+ logger.info("Time elapsed: {}", System.currentTimeMillis() - time);
}, 0, 10, TimeUnit.SECONDS);
}