Search in sources :

Example 6 with GlobalTransaction

use of io.seata.tm.api.GlobalTransaction in project seata by seata.

the class StateMachineDBTests method testCompensationStateMachineAsync.

@Disabled("https://github.com/seata/seata/issues/2564")
public void testCompensationStateMachineAsync() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 1);
    paramMap.put("barThrowException", "true");
    String stateMachineName = "simpleCompensationStateMachine";
    StateMachineInstance inst = stateMachineEngine.startAsync(stateMachineName, null, paramMap, callback);
    waittingForFinish(inst);
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    Assertions.assertTrue(ExecutionStatus.UN.equals(inst.getStatus()));
    Assertions.assertTrue(ExecutionStatus.SU.equals(inst.getCompensationStatus()));
    GlobalTransaction globalTransaction = getGlobalTransaction(inst);
    Assertions.assertNotNull(globalTransaction);
    Assertions.assertTrue(GlobalStatus.Finished.equals(globalTransaction.getStatus()));
}
Also used : HashMap(java.util.HashMap) GlobalTransaction(io.seata.tm.api.GlobalTransaction) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with GlobalTransaction

use of io.seata.tm.api.GlobalTransaction in project seata by seata.

the class StateMachineDBTests method testStatusMatchingStateMachineAsync.

@Test
public void testStatusMatchingStateMachineAsync() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 1);
    paramMap.put("barThrowException", "true");
    String stateMachineName = "simpleStatusMatchingStateMachine";
    StateMachineInstance inst = stateMachineEngine.startAsync(stateMachineName, null, paramMap, callback);
    waittingForFinish(inst);
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    Assertions.assertNotNull(inst.getException());
    Assertions.assertTrue(ExecutionStatus.UN.equals(inst.getStatus()));
    GlobalTransaction globalTransaction = getGlobalTransaction(inst);
    Assertions.assertNotNull(globalTransaction);
    Assertions.assertTrue(GlobalStatus.CommitRetrying.equals(globalTransaction.getStatus()));
}
Also used : HashMap(java.util.HashMap) GlobalTransaction(io.seata.tm.api.GlobalTransaction) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Test(org.junit.jupiter.api.Test)

Example 8 with GlobalTransaction

use of io.seata.tm.api.GlobalTransaction in project seata by seata.

the class StateMachineDBTests method testSimpleCatchesStateMachine.

@Test
public void testSimpleCatchesStateMachine() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 1);
    paramMap.put("barThrowException", "true");
    String stateMachineName = "simpleCachesStateMachine";
    StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    Assertions.assertNotNull(inst.getException());
    Assertions.assertTrue(ExecutionStatus.FA.equals(inst.getStatus()));
    GlobalTransaction globalTransaction = getGlobalTransaction(inst);
    Assertions.assertNotNull(globalTransaction);
    Assertions.assertTrue(GlobalStatus.Finished.equals(globalTransaction.getStatus()));
}
Also used : HashMap(java.util.HashMap) GlobalTransaction(io.seata.tm.api.GlobalTransaction) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Test(org.junit.jupiter.api.Test)

Example 9 with GlobalTransaction

use of io.seata.tm.api.GlobalTransaction in project seata by seata.

the class StateMachineDBTests method testCompensationAndSubStateMachine.

@Test
public void testCompensationAndSubStateMachine() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 2);
    paramMap.put("barThrowException", "true");
    String stateMachineName = "simpleStateMachineWithCompensationAndSubMachine";
    StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    Assertions.assertTrue(ExecutionStatus.UN.equals(inst.getStatus()));
    GlobalTransaction globalTransaction = getGlobalTransaction(inst);
    Assertions.assertNotNull(globalTransaction);
    Assertions.assertTrue(GlobalStatus.CommitRetrying.equals(globalTransaction.getStatus()));
}
Also used : HashMap(java.util.HashMap) GlobalTransaction(io.seata.tm.api.GlobalTransaction) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Test(org.junit.jupiter.api.Test)

Example 10 with GlobalTransaction

use of io.seata.tm.api.GlobalTransaction in project seata by seata.

the class XAModeTest2 method createGlobalTransaction.

private GlobalTransaction createGlobalTransaction() {
    String vgroup = "my_test_tx_group";
    GlobalTransactionScanner scanner = new GlobalTransactionScanner(vgroup);
    scanner.afterPropertiesSet();
    GlobalTransaction gtx = GlobalTransactionContext.getCurrentOrCreate();
    return gtx;
}
Also used : GlobalTransaction(io.seata.tm.api.GlobalTransaction) GlobalTransactionScanner(io.seata.spring.annotation.GlobalTransactionScanner)

Aggregations

GlobalTransaction (io.seata.tm.api.GlobalTransaction)27 StateMachineInstance (io.seata.saga.statelang.domain.StateMachineInstance)17 Test (org.junit.jupiter.api.Test)13 HashMap (java.util.HashMap)10 Disabled (org.junit.jupiter.api.Disabled)7 EngineExecutionException (io.seata.saga.engine.exception.EngineExecutionException)6 TransactionException (io.seata.core.exception.TransactionException)5 ExecutionException (io.seata.tm.api.TransactionalExecutor.ExecutionException)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 DruidXADataSource (com.alibaba.druid.pool.xa.DruidXADataSource)4 MysqlXADataSource (com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)4 DataSource (javax.sql.DataSource)4 XADataSource (javax.sql.XADataSource)4 PGXADataSource (org.postgresql.xa.PGXADataSource)4 StateMachineConfig (io.seata.saga.engine.StateMachineConfig)3 DbStateMachineConfig (io.seata.saga.engine.config.DbStateMachineConfig)3 DefaultStateMachineConfig (io.seata.saga.engine.impl.DefaultStateMachineConfig)3 BranchStatus (io.seata.core.model.BranchStatus)1 GlobalStatus (io.seata.core.model.GlobalStatus)1 StateInstance (io.seata.saga.statelang.domain.StateInstance)1