From ea2b18a6217e9ef7290baa4f7fe4c714a9fcb595 Mon Sep 17 00:00:00 2001 From: leezongjie Date: Wed, 28 Feb 2024 14:54:19 +0800 Subject: [PATCH] fix test --- .../test/java/org/apache/seata/rm/tcc/TccAction.java | 12 ++++++++++++ .../java/org/apache/seata/rm/tcc/TccActionImpl.java | 12 ++++++++++++ .../parser/TccActionInterceptorParserTest.java | 8 +++++++- .../parser/TccRegisterResourceParserTest.java | 10 +++++----- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/tcc/src/test/java/org/apache/seata/rm/tcc/TccAction.java b/tcc/src/test/java/org/apache/seata/rm/tcc/TccAction.java index 9f0e6f53322..ec9ea949cf9 100644 --- a/tcc/src/test/java/org/apache/seata/rm/tcc/TccAction.java +++ b/tcc/src/test/java/org/apache/seata/rm/tcc/TccAction.java @@ -17,6 +17,7 @@ package org.apache.seata.rm.tcc; import org.apache.seata.rm.tcc.api.BusinessActionContext; +import org.apache.seata.rm.tcc.api.BusinessActionContextParameter; import org.apache.seata.rm.tcc.api.LocalTCC; import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; @@ -43,6 +44,14 @@ public interface TccAction { */ boolean commit(BusinessActionContext actionContext); + /** + * Commit boolean. + * + * @param actionContext the action context + * @return the boolean + */ + boolean commitWithArg(BusinessActionContext actionContext, @BusinessActionContextParameter("tccParam") TccParam param, @Param("a") Integer a); + /** * Rollback boolean. * @@ -50,4 +59,7 @@ public interface TccAction { * @return the boolean */ boolean rollback(BusinessActionContext actionContext); + + boolean rollbackWithArg(BusinessActionContext actionContext, @BusinessActionContextParameter("tccParam") TccParam param); + } diff --git a/tcc/src/test/java/org/apache/seata/rm/tcc/TccActionImpl.java b/tcc/src/test/java/org/apache/seata/rm/tcc/TccActionImpl.java index c0012a86354..d63e67a5561 100644 --- a/tcc/src/test/java/org/apache/seata/rm/tcc/TccActionImpl.java +++ b/tcc/src/test/java/org/apache/seata/rm/tcc/TccActionImpl.java @@ -38,11 +38,23 @@ public boolean commit(BusinessActionContext actionContext) { return true; } + @Override + public boolean commitWithArg(BusinessActionContext actionContext, TccParam param, Integer a) { + return false; + } + + @Override public boolean rollback(BusinessActionContext actionContext) { return true; } + @Override + public boolean rollbackWithArg(BusinessActionContext actionContext, TccParam param) { + return false; + } + + public boolean isCommit() { return isCommit; } diff --git a/tcc/src/test/java/org/apache/seata/rm/tcc/interceptor/parser/TccActionInterceptorParserTest.java b/tcc/src/test/java/org/apache/seata/rm/tcc/interceptor/parser/TccActionInterceptorParserTest.java index cf712e8d963..0f193535537 100644 --- a/tcc/src/test/java/org/apache/seata/rm/tcc/interceptor/parser/TccActionInterceptorParserTest.java +++ b/tcc/src/test/java/org/apache/seata/rm/tcc/interceptor/parser/TccActionInterceptorParserTest.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; + +import org.apache.seata.core.context.RootContext; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.BranchType; import org.apache.seata.core.model.GlobalStatus; @@ -75,6 +77,7 @@ void parserInterfaceToProxy() { @Test public void testNestTcc_should_commit() throws Exception { //given + RootContext.unbind(); DefaultResourceManager.get(); DefaultResourceManager.mockResourceManager(BranchType.TCC, resourceManager); @@ -129,6 +132,7 @@ public void testNestTcc_should_commit() throws Exception { @Test public void testNestTcc_should_rollback() throws Exception { //given + RootContext.unbind(); DefaultResourceManager.get(); DefaultResourceManager.mockResourceManager(BranchType.TCC, resourceManager); @@ -183,6 +187,7 @@ public void testNestTcc_should_rollback() throws Exception { @Test public void testNestTcc_required_new_should_rollback_commit() throws Exception { //given + RootContext.unbind(); DefaultResourceManager.get(); DefaultResourceManager.mockResourceManager(BranchType.TCC, resourceManager); @@ -227,7 +232,7 @@ public void testNestTcc_required_new_should_rollback_commit() throws Exception { throw exx; } - Assertions.assertFalse(nestTccAction.isCommit()); + Assertions.assertTrue(nestTccAction.isCommit()); Assertions.assertTrue(tccAction.isCommit()); } @@ -237,6 +242,7 @@ public void testNestTcc_required_new_should_rollback_commit() throws Exception { @Test public void testNestTcc_required_new_should_both_commit() throws Exception { //given + RootContext.unbind(); DefaultResourceManager.get(); DefaultResourceManager.mockResourceManager(BranchType.TCC, resourceManager); diff --git a/tcc/src/test/java/org/apache/seata/rm/tcc/resource/parser/TccRegisterResourceParserTest.java b/tcc/src/test/java/org/apache/seata/rm/tcc/resource/parser/TccRegisterResourceParserTest.java index a11e12f8b1f..b7f651afae9 100644 --- a/tcc/src/test/java/org/apache/seata/rm/tcc/resource/parser/TccRegisterResourceParserTest.java +++ b/tcc/src/test/java/org/apache/seata/rm/tcc/resource/parser/TccRegisterResourceParserTest.java @@ -16,13 +16,14 @@ */ package org.apache.seata.rm.tcc.resource.parser; +import java.lang.reflect.Method; + +import org.apache.seata.rm.tcc.TccAction; import org.apache.seata.rm.tcc.TccParam; import org.apache.seata.rm.tcc.api.BusinessActionContext; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.lang.reflect.Method; - class TccRegisterResourceParserTest { @@ -30,14 +31,13 @@ class TccRegisterResourceParserTest { @Test public void testGetTwoPhaseArgs() throws Exception { - Class tccActionImpl = Class.forName("org.apache.seata.rm.tcc.TccActionImpl"); Class[] argsCommitClasses = new Class[]{BusinessActionContext.class, TccParam.class, Integer.class}; - Method commitMethod = tccActionImpl.getMethod("commit", argsCommitClasses); + Method commitMethod = TccAction.class.getMethod("commitWithArg", argsCommitClasses); Assertions.assertThrows(IllegalArgumentException.class, () -> { tccRegisterResourceParser.getTwoPhaseArgs(commitMethod, argsCommitClasses); }); Class[] argsRollbackClasses = new Class[]{BusinessActionContext.class, TccParam.class}; - Method rollbackMethod = tccActionImpl.getMethod("rollback", argsRollbackClasses); + Method rollbackMethod = TccAction.class.getMethod("rollbackWithArg", argsRollbackClasses); String[] keys = tccRegisterResourceParser.getTwoPhaseArgs(rollbackMethod, argsRollbackClasses); Assertions.assertNull(keys[0]); Assertions.assertEquals("tccParam", keys[1]);