Search in sources :

Example 16 with StateMachineInstance

use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.

the class StateMachineTests method testCompensationAndSubStateMachineWithLayout.

@Test
public void testCompensationAndSubStateMachineWithLayout() {
    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()));
}
Also used : HashMap(java.util.HashMap) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Test(org.junit.jupiter.api.Test)

Example 17 with StateMachineInstance

use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.

the class StateMachineDBTests method testStatusMatchingStateMachine.

@Test
public void testStatusMatchingStateMachine() 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.start(stateMachineName, null, paramMap);
    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);
    System.out.println(globalTransaction.getStatus());
    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 StateMachineInstance

use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.

the class StateMachineDBTests method testCompensationStateMachineForRecovery.

@Test
public void testCompensationStateMachineForRecovery() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 1);
    paramMap.put("fooThrowExceptionRandomly", "true");
    paramMap.put("barThrowExceptionRandomly", "true");
    paramMap.put("compensateFooThrowExceptionRandomly", "true");
    paramMap.put("compensateBarThrowExceptionRandomly", "true");
    String stateMachineName = "simpleCompensationStateMachineForRecovery";
    StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    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()) || ExecutionStatus.SU.equals(inst.getCompensationStatus()))) {
        System.out.println("====== GlobalStatus: " + globalTransaction.getStatus());
        Thread.sleep(2000);
        inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(inst.getId());
    }
}
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 19 with StateMachineInstance

use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.

the class StateMachineDBTests method testSimpleStateMachineWithLoopForward.

@Test
public void testSimpleStateMachineWithLoopForward() throws InterruptedException {
    long start = System.currentTimeMillis();
    List<Integer> loopList = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        loopList.add(i);
    }
    Map<String, Object> paramMap = new HashMap<>(2);
    paramMap.put("a", 1);
    paramMap.put("collection", loopList);
    paramMap.put("fooThrowException", "true");
    String stateMachineName = "simpleLoopTestStateMachine";
    StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    Assertions.assertEquals(inst.getStatus(), ExecutionStatus.UN);
    Thread.sleep(sleepTime);
    inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(inst.getId());
    Assertions.assertEquals(inst.getStatus(), ExecutionStatus.UN);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Test(org.junit.jupiter.api.Test)

Example 20 with StateMachineInstance

use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.

the class StateMachineDBTests method testSimpleCompensateStateAsUpdateMode.

@Test
public void testSimpleCompensateStateAsUpdateMode() throws Exception {
    long start = System.currentTimeMillis();
    Map<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("a", 2);
    paramMap.put("barThrowException", "true");
    paramMap.put("compensateBarThrowException", "true");
    String stateMachineName = "simpleUpdateStateMachine";
    StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
    long cost = System.currentTimeMillis() - start;
    System.out.println("====== cost :" + cost);
    Assertions.assertNotNull(inst.getException());
    Assertions.assertEquals(inst.getStatus(), ExecutionStatus.UN);
    Thread.sleep(sleepTime);
    inst = stateMachineEngine.getStateMachineConfig().getStateLogStore().getStateMachineInstance(inst.getId());
    Assertions.assertEquals(inst.getStateList().size(), 3);
}
Also used : HashMap(java.util.HashMap) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) Test(org.junit.jupiter.api.Test)

Aggregations

StateMachineInstance (io.seata.saga.statelang.domain.StateMachineInstance)113 HashMap (java.util.HashMap)80 Test (org.junit.jupiter.api.Test)76 EngineExecutionException (io.seata.saga.engine.exception.EngineExecutionException)21 GlobalTransaction (io.seata.tm.api.GlobalTransaction)17 StateMachineConfig (io.seata.saga.engine.StateMachineConfig)16 StateInstance (io.seata.saga.statelang.domain.StateInstance)16 StateInstruction (io.seata.saga.engine.pcext.StateInstruction)15 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 ForwardInvalidException (io.seata.saga.engine.exception.ForwardInvalidException)7 ProcessContext (io.seata.saga.proctrl.ProcessContext)6 People (io.seata.saga.engine.mock.DemoService.People)5 ExecutionStatus (io.seata.saga.statelang.domain.ExecutionStatus)5 Loop (io.seata.saga.statelang.domain.TaskState.Loop)5 Date (java.util.Date)5 LinkedHashMap (java.util.LinkedHashMap)5 TransactionException (io.seata.core.exception.TransactionException)4 AbstractTaskState (io.seata.saga.statelang.domain.impl.AbstractTaskState)4 List (java.util.List)4