Skip to content

Commit

Permalink
optimize: fix unit test in java 21 (apache#5863)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Sep 24, 2023
1 parent ce2f962 commit fd9a70e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v3
# step 2
- name: "Set up Java JDK"
uses: actions/setup-java@v2.5.0
uses: actions/setup-java@v3.12.0
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/checkout@v3
# step 2
- name: "Setup Java JDK"
uses: actions/setup-java@v3.9.0
uses: actions/setup-java@v3.12.0
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-ossrh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v2.4.0
# step 2
- name: "Setup Java JDK"
uses: actions/setup-java@v3.9.0
uses: actions/setup-java@v3.12.0
with:
distribution: 'zulu'
java-version: 8
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/checkout@v3
# step 2
- name: "Set up Java JDK"
uses: actions/setup-java@v2.5.0
uses: actions/setup-java@v3.12.0
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
Expand All @@ -61,7 +61,7 @@ jobs:
matrix:
java: [ 17, 21 ]
springboot: [
3.1.4 -Dspring-framework.version=6.0.12 -Pdependencies-for-springboot3-1-or-above,
3.1.4 -Dspring-framework.version=6.0.12,
3.0.11 -Dspring-framework.version=6.0.12,
]
steps:
Expand All @@ -70,7 +70,7 @@ jobs:
uses: actions/checkout@v3
# step 2
- name: "Set up Java JDK"
uses: actions/setup-java@v2.5.0
uses: actions/setup-java@v3.12.0
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
Expand Down
9 changes: 3 additions & 6 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,12 @@
</artifactSet>
<transformers>
<!-- META-INF/services -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<!-- spring相关 -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
Expand Down
6 changes: 3 additions & 3 deletions build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@
</properties>
</profile>

<!-- profile: args-for-test-by-jdk17 -->
<!-- profile: args-for-test-by-jdk17-and-above -->
<profile>
<id>args-for-test-by-jdk17</id>
<id>args-for-test-by-jdk17-and-above</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 @@ -28,7 +28,7 @@
import io.seata.common.BranchDO;
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 @@ -124,7 +124,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 Expand Up @@ -189,7 +189,7 @@ public void testAnnotationToString() throws NoSuchMethodException {
}

@Test
@DisabledOnJre(JRE.JAVA_17) // `ReflectionUtil.getAnnotationValues` does not supported java17
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}) // `ReflectionUtil.modifyStaticFinalField` does not supported java17 and above versions
public void testGetAnnotationValues() throws NoSuchMethodException, NoSuchFieldException {
Assertions.assertEquals(new LinkedHashMap<>(), ReflectionUtil
.getAnnotationValues(this.getClass().getMethod("testGetAnnotationValues").getAnnotation(Test.class)));
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 @@ -172,7 +173,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
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

0 comments on commit fd9a70e

Please sign in to comment.