Skip to content

Commit

Permalink
Support jdk17 (#3339)
Browse files Browse the repository at this point in the history
Adjust the test logic, use jdk17 to build, 8, 11, 17 to run
  • Loading branch information
robberphex authored Feb 20, 2024
1 parent 2b7a989 commit 8fef1b5
Show file tree
Hide file tree
Showing 34 changed files with 1,248 additions and 1,153 deletions.
12 changes: 0 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
version: 2
jobs:
integration-test:
docker:
- image: cimg/openjdk:8.0
working_directory: ~/sentinel
environment:
MAVEN_OPTS: -Xmx3200m
steps:
- checkout
# Run tests
- run: mvn integration-test

document-lint:
docker:
# this image is build from Dockerfile
Expand Down Expand Up @@ -49,5 +38,4 @@ workflows:
version: 2
ci:
jobs:
- integration-test
- document-lint
22 changes: 13 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ name: Sentinel CI
on:
push:
branches:
- master
- "1.8"
- "2.0"
- '*'
pull_request:
branches:
- master
Expand All @@ -17,20 +15,26 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [8, 11]
java: [8, 11, 17]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v3
- name: Setup Java for test
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
architecture: x64
cache: 'maven'

- name: Setup Java for mvn
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'

- name: Test with Maven
run: mvn --batch-mode test
run: mvn --batch-mode test -Dsurefire.jdk-toolchain-version=${{ matrix.java }}

- name: Build with Maven
run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -DminimumPriority=1
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand All @@ -48,6 +48,11 @@ jobs:
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
Expand Down
74 changes: 55 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<!-- Test libs -->
<junit.version>4.12</junit.version>
<mockito.version>2.28.2</mockito.version>
<mockito.version>3.12.4</mockito.version>
<assertj.version>3.12.1</assertj.version>
<awaitility.version>3.1.5</awaitility.version>
<powermock.version>2.0.0</powermock.version>
Expand All @@ -56,14 +56,14 @@
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.encoding>UTF-8</java.encoding>
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
<maven.compiler.version>3.12.0</maven.compiler.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
<maven.source.version>3.0.1</maven.source.version>
<maven.javadoc.version>3.0.1</maven.javadoc.version>
<maven.deploy.version>2.8.2</maven.deploy.version>
<maven.gpg.version>1.6</maven.gpg.version>
<maven.jacoco.version>0.8.3</maven.jacoco.version>
<maven.jar.version>3.1.0</maven.jar.version>
<maven.jar.version>3.3.0</maven.jar.version>
<maven.pmd.version>3.8</maven.pmd.version>
</properties>

Expand Down Expand Up @@ -189,6 +189,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand All @@ -207,18 +213,6 @@
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -271,15 +265,33 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<release>17</release>
</configuration>
</execution>
<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
<encoding>${java.encoding}</encoding>
<release>8</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<!-- CircleCI build workaround -->
<argLine>@{argLine} -Xms1024m -Xmx2048m</argLine>
Expand Down Expand Up @@ -394,6 +406,30 @@
</repository>
</distributionManagement>
</profile>
<profile>
<id>custom-test-runtime-version</id>
<activation>
<property>
<name>surefire.jdk-toolchain-version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<jdkToolchain>
<version>${surefire.jdk-toolchain-version}</version>
</jdkToolchain>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

</project>
4 changes: 2 additions & 2 deletions sentinel-adapter/sentinel-jax-rs-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.6.RELEASE</version>
<version>2.4.13</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -66,7 +66,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
</plugins>
Expand Down
5 changes: 3 additions & 2 deletions sentinel-adapter/sentinel-web-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<properties>
<servlet.api.version>3.1.0</servlet.api.version>
<spring.boot.version>2.4.13</spring.boot.version>
</properties>

<dependencies>
Expand All @@ -37,13 +38,13 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.17.RELEASE</version>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.17.RELEASE</version>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 1 addition & 11 deletions sentinel-cluster/sentinel-cluster-server-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,14 @@
<artifactId>sentinel-datasource-nacos</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.csp.sentinel.cluster;

import com.alibaba.csp.sentinel.util.TimeUtil;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

/**
* Mock support for {@link TimeUtil}
*
* @author jason
*/
@RunWith(MockitoJUnitRunner.class)
public abstract class AbstractTimeBasedTest {

private long currentMillis = 0;

public MockedStatic<TimeUtil> mockTimeUtil() {
MockedStatic<TimeUtil> mocked = Mockito.mockStatic(TimeUtil.class);
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis);
return mocked;
}

protected final void useActualTime(MockedStatic<TimeUtil> mocked) {
mocked.when(TimeUtil::currentTimeMillis).thenCallRealMethod();
}

protected final void setCurrentMillis(MockedStatic<TimeUtil> mocked, long cur) {
currentMillis = cur;
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis);
}

protected final void sleep(MockedStatic<TimeUtil> mocked, long t) {
currentMillis += t;
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis);
}

protected final void sleepSecond(MockedStatic<TimeUtil> mocked, long timeSec) {
sleep(mocked, timeSec * 1000);
}
}
Loading

0 comments on commit 8fef1b5

Please sign in to comment.