use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.
the class StateMachineDBTests method testSimpleInputAssignmentStateMachine.
@Test
public void testSimpleInputAssignmentStateMachine() {
long start = System.currentTimeMillis();
Map<String, Object> paramMap = new HashMap<>(1);
paramMap.put("a", 1);
String stateMachineName = "simpleInputAssignmentStateMachine";
StateMachineInstance instance = stateMachineEngine.start(stateMachineName, null, paramMap);
String businessKey = instance.getStateList().get(0).getBusinessKey();
Assertions.assertNotNull(businessKey);
System.out.println("====== businessKey :" + businessKey);
String contextBusinessKey = (String) instance.getEndParams().get(instance.getStateList().get(0).getName() + DomainConstants.VAR_NAME_BUSINESSKEY);
Assertions.assertNotNull(contextBusinessKey);
System.out.println("====== context businessKey :" + businessKey);
long cost = System.currentTimeMillis() - start;
System.out.println("====== cost :" + cost);
}
use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.
the class StateMachineDBTests method simpleChoiceTestStateMachineAsyncConcurrently.
@Test
@Disabled("https://github.com/seata/seata/issues/2414#issuecomment-639546811")
public void simpleChoiceTestStateMachineAsyncConcurrently() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(100);
final List<Exception> exceptions = new ArrayList<>();
final AsyncCallback asyncCallback = new AsyncCallback() {
@Override
public void onFinished(ProcessContext context, StateMachineInstance stateMachineInstance) {
countDownLatch.countDown();
}
@Override
public void onError(ProcessContext context, StateMachineInstance stateMachineInstance, Exception exp) {
countDownLatch.countDown();
exceptions.add(exp);
}
};
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int j = 0; j < 10; j++) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("a", 1);
paramMap.put("barThrowException", "false");
String stateMachineName = "simpleCompensationStateMachine";
try {
stateMachineEngine.startAsync(stateMachineName, null, paramMap, asyncCallback);
} catch (Exception e) {
countDownLatch.countDown();
exceptions.add(e);
}
}
}
});
t.start();
}
countDownLatch.await(10000, TimeUnit.MILLISECONDS);
if (exceptions.size() > 0) {
Assertions.fail(exceptions.get(0));
}
long cost = System.currentTimeMillis() - start;
System.out.println("====== cost :" + cost);
}
use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.
the class StateMachineTests method testSimpleScriptTaskStateMachine.
@Test
public void testSimpleScriptTaskStateMachine() {
long start = System.currentTimeMillis();
Map<String, Object> paramMap = new HashMap<>(1);
paramMap.put("a", 1);
String stateMachineName = "simpleScriptTaskStateMachine";
StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
long cost = System.currentTimeMillis() - start;
System.out.println("====== cost :" + cost);
Assertions.assertTrue(ExecutionStatus.SU.equals(inst.getStatus()));
Assertions.assertNotNull(inst.getEndParams().get("scriptStateResult"));
start = System.currentTimeMillis();
inst = stateMachineEngine.start(stateMachineName, null, paramMap);
cost = System.currentTimeMillis() - start;
System.out.println("====== cost :" + cost);
Assertions.assertTrue(ExecutionStatus.SU.equals(inst.getStatus()));
start = System.currentTimeMillis();
paramMap.put("scriptThrowException", true);
inst = stateMachineEngine.start(stateMachineName, null, paramMap);
cost = System.currentTimeMillis() - start;
System.out.println("====== cost :" + cost);
Assertions.assertTrue(ExecutionStatus.FA.equals(inst.getStatus()));
}
use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.
the class StateMachineTests method testSimpleStateMachineWithAsyncState.
@Test
public void testSimpleStateMachineWithAsyncState() {
long start = System.currentTimeMillis();
Map<String, Object> paramMap = new HashMap<>(1);
paramMap.put("a", 1);
String stateMachineName = "simpleStateMachineWithAsyncState";
StateMachineInstance inst = stateMachineEngine.start(stateMachineName, null, paramMap);
long cost = System.currentTimeMillis() - start;
System.out.println("====== cost :" + cost);
Assertions.assertTrue(ExecutionStatus.SU.equals(inst.getStatus()));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of io.seata.saga.statelang.domain.StateMachineInstance in project seata by seata.
the class StateMachineTests method testSimpleCatchesStateMachine.
@Test
public void testSimpleCatchesStateMachine() {
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()));
}
Aggregations