Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
leezongjie committed Feb 28, 2024
1 parent 4f2612b commit ea2b18a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
12 changes: 12 additions & 0 deletions tcc/src/test/java/org/apache/seata/rm/tcc/TccAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,11 +44,22 @@ 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.
*
* @param actionContext the action context
* @return the boolean
*/
boolean rollback(BusinessActionContext actionContext);

boolean rollbackWithArg(BusinessActionContext actionContext, @BusinessActionContextParameter("tccParam") TccParam param);

}
12 changes: 12 additions & 0 deletions tcc/src/test/java/org/apache/seata/rm/tcc/TccActionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +77,7 @@ void parserInterfaceToProxy() {
@Test
public void testNestTcc_should_commit() throws Exception {
//given
RootContext.unbind();
DefaultResourceManager.get();
DefaultResourceManager.mockResourceManager(BranchType.TCC, resourceManager);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());

}
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
*/
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 {

TccRegisterResourceParser tccRegisterResourceParser = new TccRegisterResourceParser();

@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]);
Expand Down

0 comments on commit ea2b18a

Please sign in to comment.