Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: fix unit test in java 21 #5862

Merged
merged 11 commits into from
Sep 24, 2023
2 changes: 1 addition & 1 deletion .github/workflows/license-checker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
log: info
config: .licenserc.yaml
mode: check
# step 5 heck dependencies
# step 5 check dependencies
- name: Check Dependencies' License
uses: apache/skywalking-eyes/dependency@8fc52baabc14c86294d96034bcc194cfa7f76b05
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-druid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 8, 11, 17 ]
java: [ 8, 11, 17, 21 ]
druid: [
1.2.19,
#1.2.18, # Unit test triggered a bug in Druid, see the commit https://github.com/alibaba/druid/commit/6c493f852852fb287ed5fd31ee16c27ead0ea5cf
Expand All @@ -34,7 +34,7 @@ jobs:
1.2.1,
1.2.0,

# not support druid:1.x
# not support druid:1.1.x
#1.1.24,
#1.1.23,
#1.1.22,
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 8, 11, 17 ]
java: [ 8, 11, 17, 21 ]
springboot: [
2.7.9 -Dspring-framework.version=5.3.25,
2.6.14 -Dspring-framework.version=5.3.24,
2.5.14 -Dspring-framework.version=5.3.20,
2.7.16 -Dspring-framework.version=5.3.30,
2.6.15 -Dspring-framework.version=5.3.27,
2.5.15 -Dspring-framework.version=5.3.27,
2.4.13 -Dspring-framework.version=5.3.13,
2.3.12.RELEASE -Dspring-framework.version=5.2.15.RELEASE,
2.2.13.RELEASE -Dspring-framework.version=5.2.12.RELEASE,
Expand Down Expand Up @@ -59,9 +59,10 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 17 ]
java: [ 17, 21 ]
springboot: [
3.0.4 -Dspring-framework.version=6.0.6 -Dspring-boot-for-server.version=2.5.14 -Dspring-framework-for-server.version=5.3.20 -Dkotlin-maven-plugin.version=1.7.22
3.1.4 -Dspring-framework.version=6.0.12,
3.0.11 -Dspring-framework.version=6.0.12,
]
steps:
# step 1
Expand All @@ -79,7 +80,7 @@ jobs:
# step 4
- name: "Test with Maven"
run: |
./mvnw -T 4C clean test -Dspring-boot.version=${{ matrix.springboot }} -Dcheckstyle.skip=true -Dlicense.skip=true -e -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn;
./mvnw -T 4C clean test -Dspring-boot.version=${{ matrix.springboot }} -Dspring-boot-for-server.version=2.5.14 -Dspring-framework-for-server.version=5.3.20 -Dkotlin-maven-plugin.version=1.7.22 -Dcheckstyle.skip=false -Dlicense.skip=false -e -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn;

# job 3
arm64-test:
Expand All @@ -88,9 +89,9 @@ jobs:
fail-fast: false
matrix:
springboot: [
2.7.9 -Dspring-framework.version=5.3.25,
2.6.14 -Dspring-framework.version=5.3.24,
2.5.14 -Dspring-framework.version=5.3.20,
2.7.16 -Dspring-framework.version=5.3.30,
2.6.15 -Dspring-framework.version=5.3.27,
2.5.15 -Dspring-framework.version=5.3.27,
2.4.13 -Dspring-framework.version=5.3.13,
2.3.12.RELEASE -Dspring-framework.version=5.2.15.RELEASE,
2.2.13.RELEASE -Dspring-framework.version=5.2.12.RELEASE,
Expand Down
6 changes: 3 additions & 3 deletions build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,11 @@
</properties>
</profile>

<!-- profile: args-for-test-by-jdk17 -->
<!-- profile: args-for-test-by-jdk17-and-above-versions -->
<profile>
<id>args-for-test-by-jdk17</id>
<id>args-for-test-by-jdk17-and-above-versions</id>
<activation>
<jdk>17</jdk>
<jdk>[17,)</jdk>
</activation>
<properties>
<maven.surefire.argLine>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public class CompressUtilTest {


@Test
@DisabledOnJre(JRE.JAVA_17)
public void testCompress() throws IOException {
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11})
public void testCompress1() throws IOException {
Assertions.assertArrayEquals(compressedBytes1,
CompressUtil.compress(originBytes));
}

@Test
@EnabledOnJre(JRE.JAVA_17)
public void testCompressForJava17() throws IOException {
@DisabledOnJre({JRE.JAVA_8, JRE.JAVA_11})
public void testCompress2() throws IOException {
Assertions.assertArrayEquals(compressedBytes2,
CompressUtil.compress(originBytes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;

public class ReflectionUtilTest {
Expand Down Expand Up @@ -100,7 +100,7 @@ public void testGetInterfaces() {
}

@Test
@DisabledOnJre(JRE.JAVA_17) // `ReflectionUtil.modifyStaticFinalField` does not supported java17
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) // `ReflectionUtil.modifyStaticFinalField` does not supported java17 and above versions
public void testModifyStaticFinalField() throws NoSuchFieldException, IllegalAccessException {
Assertions.assertEquals("hello", testValue);
ReflectionUtil.modifyStaticFinalField(ReflectionUtilTest.class, "testValue", "hello world");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.seata.common.holder.ObjectHolder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -124,7 +125,12 @@ void testToStringAndCycleDependency() throws Exception {
//case: Charset
Assertions.assertEquals("UTF-8", StringUtils.toString(StandardCharsets.UTF_8));
//case: Thread
Assertions.assertEquals("Thread[main,5,main]", StringUtils.toString(Thread.currentThread()));
try {
Assertions.assertEquals("Thread[main,5,main]", StringUtils.toString(Thread.currentThread()));
} catch (AssertionFailedError e) {
// for java21 and above
Assertions.assertEquals("Thread[#" + Thread.currentThread().getId() + ",main,5,main]", StringUtils.toString(Thread.currentThread()));
}

//case: Date
Date date = new Date(2021 - 1900, 6 - 1, 15);
Expand Down
14 changes: 14 additions & 0 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
<zstd.version>1.5.0-4</zstd.version>
<xstream.version>1.4.20</xstream.version>

<!-- The `httpcore` and `httpclient` have been removed in spring-boot 3.1.0 and above. -->
<httpcore.version>4.4.16</httpcore.version>
<httpclient.version>4.5.14</httpclient.version>

<jwt.version>0.10.5</jwt.version>
<prometheus.client.version>0.6.0</prometheus.client.version>
<logback.version>1.2.9</logback.version>
Expand Down Expand Up @@ -700,6 +704,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpcore.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.mockito.Mockito;

Expand All @@ -43,7 +43,7 @@
*
* @author ggndnn
*/
@DisabledOnJre(JRE.JAVA_17) // `ReflectionUtil.modifyStaticFinalField` does not supported java17
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) // `ReflectionUtil.modifyStaticFinalField` does not supported java17 and above versions
public class ConnectionProxyTest {
private DataSourceProxy dataSourceProxy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.mockito.Mockito;

Expand All @@ -44,7 +44,7 @@
*
* @author ggndnn
*/
@DisabledOnJre(JRE.JAVA_17) // `ReflectionUtil.modifyStaticFinalField` does not supported java17
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) // `ReflectionUtil.modifyStaticFinalField` does not supported java17 and above versions
public class AbstractDMLBaseExecutorTest {
private ConnectionProxy connectionProxy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void test_handleRetryRollbacking() throws TransactionException, Interrupt
}

@Test
@DisabledOnJre(JRE.JAVA_17) // `ReflectionUtil.modifyStaticFinalField` does not supported java17
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) // `ReflectionUtil.modifyStaticFinalField` does not supported java17 and above versions
public void test_handleRetryRollbackingTimeOut() throws TransactionException, InterruptedException, NoSuchFieldException, IllegalAccessException {
String xid = core.begin(applicationId, txServiceGroup, txName, 10);
Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);
Expand All @@ -185,7 +185,7 @@ public void test_handleRetryRollbackingTimeOut() throws TransactionException, In
}

@Test
@DisabledOnJre(JRE.JAVA_17) // `ReflectionUtil.modifyStaticFinalField` does not supported java17
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) // `ReflectionUtil.modifyStaticFinalField` does not supported java17 and above versions
public void test_handleRetryRollbackingTimeOut_unlock() throws TransactionException, InterruptedException,
NoSuchFieldException, IllegalAccessException {
String xid = core.begin(applicationId, txServiceGroup, txName, 10);
Expand Down
Loading