Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/master-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
java: [ '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]')"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]')"

Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 27 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.github.switcherapi</groupId>
<artifactId>switcher-client</artifactId>
<packaging>jar</packaging>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>

<name>Switcher Client</name>
<description>Switcher Client SDK for working with Switcher API</description>
Expand Down Expand Up @@ -51,38 +51,40 @@
<maven.compiler.target>${java.version}</maven.compiler.target>

<!-- rest/json libs -->
<jersey-client.version>3.1.5</jersey-client.version>
<jersey-hk2.version>3.1.5</jersey-hk2.version>
<jersey-media-json-jackson.version>3.1.5</jersey-media-json-jackson.version>
<jersey-client.version>3.1.6</jersey-client.version>
<jersey-hk2.version>3.1.6</jersey-hk2.version>
<jersey-media-json-jackson.version>3.1.6</jersey-media-json-jackson.version>
<gson.version>2.10.1</gson.version>

<!-- utils -->
<commons-lang3.version>3.14.0</commons-lang3.version>
<commons-net.version>3.10.0</commons-net.version>
<log4j.version>2.23.0</log4j.version>
<log4j.version>2.23.1</log4j.version>

<!-- test -->
<okhttp.version>5.0.0-alpha.12</okhttp.version>
<okhttp.version>5.0.0-alpha.14</okhttp.version>
<junit.version>5.10.2</junit.version>
<junit-pioneer.version>2.2.0</junit-pioneer.version>

<!-- Plugins -->
<maven-compiler.version>3.12.1</maven-compiler.version>
<maven-source.version>3.3.0</maven-source.version>
<maven-surefire.version>3.2.5</maven-surefire.version>
<maven-gpg.version>3.1.0</maven-gpg.version>
<sonar.version>3.10.0.2594</sonar.version>
<jacoco.version>0.8.11</jacoco.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-jar-plugin.version>3.4.1</maven-jar-plugin.version>
<maven-gpg-plugin.version>3.2.4</maven-gpg-plugin.version>
<sonar-maven-plugin.version>3.11.0.3922</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>

<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>java</sonar.language>
<sonar.coverage.exclusions>
**/model/**/*.java,
**/exception/**/*.java,
**/service/validators/RegexValidatorV8.java
</sonar.coverage.exclusions>
**/model/**/*.java,
**/exception/**/*.java,
**/service/validators/RegexValidatorV8.java
</sonar.coverage.exclusions>
</properties>

<dependencies>
Expand All @@ -102,7 +104,7 @@
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey-media-json-jackson.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down Expand Up @@ -242,7 +244,7 @@
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.version}</version>
<version>${sonar-maven-plugin.version}</version>
<executions>
<execution>
<phase>verify</phase>
Expand All @@ -263,7 +265,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source.version}</version>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -276,7 +278,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-source.version}</version>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -289,7 +291,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg.version}</version>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -311,7 +313,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
Expand All @@ -321,7 +323,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<version>${jacoco-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
Expand All @@ -339,7 +341,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>
--add-opens java.base/java.util=ALL-UNNAMED
Expand All @@ -352,7 +354,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-source.version}</version>
<version>${maven-jar-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/log4j2.properties</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <br>Threads are only created when the time calculated for the next run is lower than the current time.
Expand All @@ -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.
Expand All @@ -36,14 +45,17 @@ 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);
}
}

@Override
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down