Solon v3.7.3

场景5:单步前进(或调试)

</> markdown
2025年12月9日 下午12:18:55

solon-flow 的执行(或流动),支持深度控制。比如:只前进一层(就是单步前进了)

1、配置

id: demo1
layout:
  - id: node_1txlypkthu
    type: start
    title: 开始
    link:
      - nextId: node_ot8buxm6ac
  - id: node_ot8buxm6ac
    title: 活动节点1
    link:
      - nextId: node_v1uc2rbtq
  - id: node_v1uc2rbtq
    type: exclusive
    title: 排他网关1
    link:
      - nextId: node_focvfre5rq
        title: ''
      - nextId: node_pzf5u4xbv8
        title: ''
        condition: a > 3
  - id: node_focvfre5rq
    title: 活动节点2
    link:
      - nextId: node_taosvt7gh
  - id: node_pzf5u4xbv8
    title: 活动节点3
    link:
      - nextId: node_xdntd2nsfe
  - id: node_xdntd2nsfe
    type: exclusive
    title: 排他网关2
    link:
      - nextId: node_ot8buxm6ac
        condition: b > 5
      - nextId: node_taosvt7gh
  - id: node_taosvt7gh
    type: end
    title: 结束

2、测试代码

(FlowContext:lastNode 需要 v3.7.4 后支持 )注意这两个参数:flowContext.lastNode(), 1,使用上次最后执行的节点,且执行深度为1(即前进一步)

public class StepBackflowTest {
    private String graphId = "backflow";

    @Test
    public void case1() throws Throwable {
        FlowEngine flowEngine = FlowEngine.newInstance();
        flowEngine.load("classpath:flow/stateless/*.yml");


        FlowContext flowContext = FlowContext.of("x1")
                .put("a", 4)
                .put("b", 6);

        flowEngine.eval(graphId, flowContext.lastNode(), 1, flowContext);
        System.out.println(flowContext.lastNode().getTitle());
        Assertions.assertEquals("活动节点1", flowContext.lastNode().getTitle());

        flowEngine.eval(graphId, flowContext.lastNode(), 1, flowContext);
        System.out.println(flowContext.lastNode().getTitle());
        Assertions.assertEquals("排他网关1", flowContext.lastNode().getTitle());

        flowEngine.eval(graphId, flowContext.lastNode(), 1, flowContext);
        System.out.println(flowContext.lastNode().getTitle());
        Assertions.assertEquals("活动节点3", flowContext.lastNode().getTitle());

        flowEngine.eval(graphId, flowContext.lastNode(), 1, flowContext);
        System.out.println(flowContext.lastNode().getTitle());
        Assertions.assertEquals("排他网关2", flowContext.lastNode().getTitle());

        flowEngine.eval(graphId, flowContext.lastNode(), 1, flowContext);
        System.out.println(flowContext.lastNode().getTitle());
        Assertions.assertEquals("活动节点1", flowContext.lastNode().getTitle());
    }
}