This is an automated email from the ASF dual-hosted git repository. yixia pushed a commit to branch 2.3.0 in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.3.0 by this push: new 35291d2576 optimize: fix 2.3.0 UT and update NOTICE (#7172) 35291d2576 is described below commit 35291d2576a73fcae6926033cad7bade0af779ea Author: wt_better <yixia...@alibaba-inc.com> AuthorDate: Thu Feb 20 16:47:54 2025 +0800 optimize: fix 2.3.0 UT and update NOTICE (#7172) --- .../tm/api/DefaultFailureHandlerImplTest.java | 48 ++++++++++++---------- distribution/NOTICE.md | 4 +- .../tm/api/DefaultFailureHandlerImplTest.java | 42 ++++++++++--------- 3 files changed, 51 insertions(+), 43 deletions(-) diff --git a/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java b/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java index 34567dd536..a273b5e747 100644 --- a/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java +++ b/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java @@ -21,10 +21,12 @@ import java.lang.reflect.Field; import io.netty.util.HashedWheelTimer; import io.seata.core.context.RootContext; import io.seata.tm.api.transaction.MyRuntimeException; +import org.apache.seata.common.util.ReflectionUtil; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.GlobalStatus; import org.apache.seata.core.model.TransactionManager; import org.apache.seata.tm.TransactionManagerHolder; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -37,10 +39,8 @@ class DefaultFailureHandlerImplTest { private static final String DEFAULT_XID = "1234567890"; private static GlobalStatus globalStatus = GlobalStatus.Begin; - @BeforeAll - public static void init() { - - TransactionManagerHolder.set(new TransactionManager() { + private TransactionManager getTransactionManager() { + return new TransactionManager() { @Override public String begin(String applicationId, String transactionServiceGroup, String name, int timeout) throws TransactionException { @@ -66,22 +66,26 @@ class DefaultFailureHandlerImplTest { public GlobalStatus globalReport(String xid, GlobalStatus globalStatus) throws TransactionException { return globalStatus; } - }); + }; } @Test - void onBeginFailure() { + void onBeginFailure() throws Exception { RootContext.bind(DEFAULT_XID); - DefaultGlobalTransaction tx = (DefaultGlobalTransaction)GlobalTransactionContext.getCurrentOrCreate(); + DefaultGlobalTransaction tx = (DefaultGlobalTransaction) GlobalTransactionContext.getCurrentOrCreate(); + ReflectionUtil.setFieldValue(tx.getInstance(), "transactionManager", getTransactionManager()); + FailureHandler failureHandler = new DefaultFailureHandlerImpl(); failureHandler.onBeginFailure(tx, new MyRuntimeException("").getCause()); } @Test - void onCommitFailure() throws Exception{ + void onCommitFailure() throws Exception { RootContext.bind(DEFAULT_XID); - DefaultGlobalTransaction tx = (DefaultGlobalTransaction)GlobalTransactionContext.getCurrentOrCreate(); + DefaultGlobalTransaction tx = (DefaultGlobalTransaction) GlobalTransactionContext.getCurrentOrCreate(); + ReflectionUtil.setFieldValue(tx.getInstance(), "transactionManager", getTransactionManager()); + FailureHandler failureHandler = new DefaultFailureHandlerImpl(); failureHandler.onCommitFailure(tx, new MyRuntimeException("").getCause()); @@ -92,22 +96,22 @@ class DefaultFailureHandlerImplTest { HashedWheelTimer timer = (HashedWheelTimer) field.get(failureHandler); // assert timer pendingCount: first time is 1 Long pendingTimeout = timer.pendingTimeouts(); - Assertions.assertEquals(pendingTimeout,1L); + Assertions.assertEquals(pendingTimeout, 1L); //set globalStatus - globalStatus= GlobalStatus.Committed; - Thread.sleep(25*1000L); + globalStatus = GlobalStatus.Committed; + Thread.sleep(25 * 1000L); pendingTimeout = timer.pendingTimeouts(); - LOGGER.info("pendingTimeout {}" ,pendingTimeout); + LOGGER.info("pendingTimeout {}", pendingTimeout); //all timer is done - Assertions.assertEquals(pendingTimeout,0L); + Assertions.assertEquals(pendingTimeout, 0L); } @Test void onRollbackFailure() throws Exception { - - RootContext.bind(DEFAULT_XID); - DefaultGlobalTransaction tx = (DefaultGlobalTransaction)GlobalTransactionContext.getCurrentOrCreate(); + DefaultGlobalTransaction tx = (DefaultGlobalTransaction) GlobalTransactionContext.getCurrentOrCreate(); + ReflectionUtil.setFieldValue(tx.getInstance(), "transactionManager", getTransactionManager()); + FailureHandler failureHandler = new DefaultFailureHandlerImpl(); failureHandler.onRollbackFailure(tx, new MyRuntimeException("").getCause()); @@ -119,14 +123,14 @@ class DefaultFailureHandlerImplTest { HashedWheelTimer timer = (HashedWheelTimer) field.get(failureHandler); // assert timer pendingCount: first time is 1 Long pendingTimeout = timer.pendingTimeouts(); - Assertions.assertEquals(pendingTimeout,1L); + Assertions.assertEquals(pendingTimeout, 1L); //set globalStatus - globalStatus= GlobalStatus.Rollbacked; - Thread.sleep(25*1000L); + globalStatus = GlobalStatus.Rollbacked; + Thread.sleep(25 * 1000L); pendingTimeout = timer.pendingTimeouts(); - LOGGER.info("pendingTimeout {}" ,pendingTimeout); + LOGGER.info("pendingTimeout {}", pendingTimeout); //all timer is done - Assertions.assertEquals(pendingTimeout,0L); + Assertions.assertEquals(pendingTimeout, 0L); } diff --git a/distribution/NOTICE.md b/distribution/NOTICE.md index 04487a60a9..c1c82dd611 100644 --- a/distribution/NOTICE.md +++ b/distribution/NOTICE.md @@ -358,7 +358,7 @@ Please copy database driver dependencies, such as `mysql-connector-java.jar`, to │ ├── tomcat-embed-core-9.0.98.jar │ ├── tomcat-embed-el-9.0.98.jar │ ├── tomcat-embed-websocket-9.0.98.jar - │ ├── xstream-1.4.20.jar + │ ├── xstream-1.4.21.jar │ ├── zookeeper-3.7.2.jar │ ├── zookeeper-jute-3.7.2.jar │ └── zstd-jni-1.5.0-4.jar @@ -778,7 +778,7 @@ Please copy database driver dependencies, such as `mysql-connector-java.jar`, to │ ├── tomcat-embed-core-9.0.98.jar │ ├── tomcat-embed-el-9.0.98.jar │ ├── tomcat-embed-websocket-9.0.98.jar - │ ├── xstream-1.4.20.jar + │ ├── xstream-1.4.21.jar │ ├── zookeeper-3.7.2.jar │ ├── zookeeper-jute-3.7.2.jar │ └── zstd-jni-1.5.0-4.jar diff --git a/tm/src/test/java/org/apache/seata/tm/api/DefaultFailureHandlerImplTest.java b/tm/src/test/java/org/apache/seata/tm/api/DefaultFailureHandlerImplTest.java index aff5518470..4ef4f2dfae 100644 --- a/tm/src/test/java/org/apache/seata/tm/api/DefaultFailureHandlerImplTest.java +++ b/tm/src/test/java/org/apache/seata/tm/api/DefaultFailureHandlerImplTest.java @@ -18,14 +18,13 @@ package org.apache.seata.tm.api; import io.netty.util.HashedWheelTimer; +import org.apache.seata.common.util.ReflectionUtil; import org.apache.seata.core.context.RootContext; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.GlobalStatus; import org.apache.seata.core.model.TransactionManager; -import org.apache.seata.tm.TransactionManagerHolder; import org.apache.seata.tm.api.transaction.MyRuntimeException; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,10 +38,8 @@ class DefaultFailureHandlerImplTest { private static final String DEFAULT_XID = "1234567890"; private static GlobalStatus globalStatus = GlobalStatus.Begin; - @BeforeAll - public static void init() { - - TransactionManagerHolder.set(new TransactionManager() { + private TransactionManager getTransactionManager() { + return new TransactionManager() { @Override public String begin(String applicationId, String transactionServiceGroup, String name, int timeout) throws TransactionException { @@ -68,22 +65,27 @@ class DefaultFailureHandlerImplTest { public GlobalStatus globalReport(String xid, GlobalStatus globalStatus) throws TransactionException { return globalStatus; } - }); + }; } @Test - void onBeginFailure() { + void onBeginFailure() throws Exception { RootContext.bind(DEFAULT_XID); GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate(); + ReflectionUtil.setFieldValue(tx, "transactionManager", getTransactionManager()); + FailureHandler failureHandler = new DefaultFailureHandlerImpl(); failureHandler.onBeginFailure(tx, new MyRuntimeException("").getCause()); } @Test - void onCommitFailure() throws Exception{ + void onCommitFailure() throws Exception { RootContext.bind(DEFAULT_XID); GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate(); + //TransactionManagerHolder.set has interaction, using globalTransaction instance level tm + ReflectionUtil.setFieldValue(tx, "transactionManager", getTransactionManager()); + FailureHandler failureHandler = new DefaultFailureHandlerImpl(); failureHandler.onCommitFailure(tx, new MyRuntimeException("").getCause()); @@ -94,14 +96,14 @@ class DefaultFailureHandlerImplTest { HashedWheelTimer timer = (HashedWheelTimer) field.get(failureHandler); // assert timer pendingCount: first time is 1 Long pendingTimeout = timer.pendingTimeouts(); - Assertions.assertEquals(pendingTimeout,1L); + Assertions.assertEquals(pendingTimeout, 1L); //set globalStatus - globalStatus= GlobalStatus.Committed; - Thread.sleep(25*1000L); + globalStatus = GlobalStatus.Committed; + Thread.sleep(25 * 1000L); pendingTimeout = timer.pendingTimeouts(); - LOGGER.info("pendingTimeout {}" ,pendingTimeout); + LOGGER.info("pendingTimeout {}", pendingTimeout); //all timer is done - Assertions.assertEquals(pendingTimeout,0L); + Assertions.assertEquals(pendingTimeout, 0L); } @Test @@ -110,6 +112,8 @@ class DefaultFailureHandlerImplTest { RootContext.bind(DEFAULT_XID); GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate(); + ReflectionUtil.setFieldValue(tx, "transactionManager", getTransactionManager()); + FailureHandler failureHandler = new DefaultFailureHandlerImpl(); failureHandler.onRollbackFailure(tx, new MyRuntimeException("").getCause()); @@ -120,14 +124,14 @@ class DefaultFailureHandlerImplTest { HashedWheelTimer timer = (HashedWheelTimer) field.get(failureHandler); // assert timer pendingCount: first time is 1 Long pendingTimeout = timer.pendingTimeouts(); - Assertions.assertEquals(pendingTimeout,1L); + Assertions.assertEquals(pendingTimeout, 1L); //set globalStatus - globalStatus= GlobalStatus.Rollbacked; - Thread.sleep(25*1000L); + globalStatus = GlobalStatus.Rollbacked; + Thread.sleep(25 * 1000L); pendingTimeout = timer.pendingTimeouts(); - LOGGER.info("pendingTimeout {}" ,pendingTimeout); + LOGGER.info("pendingTimeout {}", pendingTimeout); //all timer is done - Assertions.assertEquals(pendingTimeout,0L); + Assertions.assertEquals(pendingTimeout, 0L); } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org