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()));
}
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()));
}
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());
}
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()));
}
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()));
}
Aggregations