Search in sources :

Example 16 with GlobalTransaction

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

the class StateMachineDBTests method testCompensationStateMachine.

@Test
public void testCompensationStateMachine() 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.start(stateMachineName, null, paramMap);
    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);
    // End with Rollbacked = Finished
    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 17 with GlobalTransaction

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

the class StateMachineDBTests method testCompensationAndSubStateMachineLayout.

@Test
public void testCompensationAndSubStateMachineLayout() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 2);
    paramMap.put("barThrowException", "true");
    String stateMachineName = "simpleStateMachineWithCompensationAndSubMachine_layout";
    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 18 with GlobalTransaction

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

the class StateMachineDBTests method doTestStateMachineCustomRecoverStrategyOnTimeout.

private void doTestStateMachineCustomRecoverStrategyOnTimeout(Map<String, Object> paramMap) throws Exception {
    long start = System.currentTimeMillis();
    String stateMachineName = "simpleStateMachineWithRecoverStrategy";
    StateMachineInstance inst;
    try {
        inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    } catch (EngineExecutionException e) {
        e.printStackTrace();
        inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(e.getStateMachineInstanceId());
    }
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    GlobalTransaction globalTransaction = getGlobalTransaction(inst);
    Assertions.assertNotNull(globalTransaction);
    System.out.println("====== GlobalStatus: " + globalTransaction.getStatus());
    // waiting for global transaction recover
    while (!(ExecutionStatus.SU.equals(inst.getStatus()) && GlobalStatus.Finished.equals(globalTransaction.getStatus()))) {
        System.out.println("====== GlobalStatus: " + globalTransaction.getStatus());
        System.out.println("====== StateMachineInstanceStatus: " + inst.getStatus());
        Thread.sleep(2000);
        inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(inst.getId());
    }
    Assertions.assertTrue(ExecutionStatus.SU.equals(inst.getStatus()));
    Assertions.assertNull(inst.getCompensationStatus());
}
Also used : GlobalTransaction(io.seata.tm.api.GlobalTransaction) EngineExecutionException(io.seata.saga.engine.exception.EngineExecutionException) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance)

Example 19 with GlobalTransaction

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

the class StateMachineDBTests method doTestStateMachineTransTimeout.

private void doTestStateMachineTransTimeout(Map<String, Object> paramMap) throws Exception {
    long start = System.currentTimeMillis();
    String stateMachineName = "simpleCompensationStateMachine";
    StateMachineInstance inst;
    try {
        inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    } catch (EngineExecutionException e) {
        e.printStackTrace();
        inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(e.getStateMachineInstanceId());
    }
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    GlobalTransaction globalTransaction = getGlobalTransaction(inst);
    Assertions.assertNotNull(globalTransaction);
    System.out.println("====== GlobalStatus: " + globalTransaction.getStatus());
    // waiting for global transaction recover
    while (!ExecutionStatus.SU.equals(inst.getCompensationStatus())) {
        System.out.println("====== GlobalStatus: " + globalTransaction.getStatus());
        Thread.sleep(2000);
        inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(inst.getId());
    }
    Assertions.assertTrue(ExecutionStatus.UN.equals(inst.getStatus()) || ExecutionStatus.SU.equals(inst.getStatus()));
    Assertions.assertTrue(ExecutionStatus.SU.equals(inst.getCompensationStatus()));
}
Also used : GlobalTransaction(io.seata.tm.api.GlobalTransaction) EngineExecutionException(io.seata.saga.engine.exception.EngineExecutionException) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance)

Example 20 with GlobalTransaction

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

the class StateMachineDBTests method testCompensationAndSubStateMachineAsync.

@Test
@Disabled("https://github.com/seata/seata/issues/2414#issuecomment-651526068")
public void testCompensationAndSubStateMachineAsync() 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.startAsync(stateMachineName, null, paramMap, callback);
    waittingForFinish(inst);
    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) Disabled(org.junit.jupiter.api.Disabled)

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