Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cola状态机,对多分支流转情况,会导致checkCondition重复执行问题 #389

Open
xuyiyu opened this issue Jan 17, 2023 · 0 comments

Comments

@xuyiyu
Copy link

xuyiyu commented Jan 17, 2023

比如:基于checkCondition的返回值走不同的状态机,但是checkCondition需要走一个复杂的调用逻辑,会导致执行比较慢,这块是否有更好的调用方式?或者是否有推荐的使用方式
`/**

  • 测试选择分支,针对同一个事件:EVENT1
  • if condition == "1", STATE1 --> STATE1
  • if condition == "2" , STATE1 --> STATE2
  • if condition == "3" , STATE1 --> STATE3
    */
    @test
    public void testChoice(){
    StateMachineBuilder<StateMachineTest.States, StateMachineTest.Events, Context> builder = StateMachineBuilderFactory.create();
    builder.internalTransition()
    .within(StateMachineTest.States.STATE1)
    .on(StateMachineTest.Events.EVENT1)
    .when(checkCondition1())
    .perform(doAction());
    builder.externalTransition()
    .from(StateMachineTest.States.STATE1)
    .to(StateMachineTest.States.STATE2)
    .on(StateMachineTest.Events.EVENT1)
    .when(checkCondition2())
    .perform(doAction());
    builder.externalTransition()
    .from(StateMachineTest.States.STATE1)
    .to(StateMachineTest.States.STATE3)
    .on(StateMachineTest.Events.EVENT1)
    .when(checkCondition3())
    .perform(doAction());
    StateMachine<StateMachineTest.States, StateMachineTest.Events, Context> stateMachine = builder.build("ChoiceConditionMachine");
    StateMachineTest.States target1 = stateMachine.fireEvent(StateMachineTest.States.STATE1, StateMachineTest.Events.EVENT1, new Context("1"));
    Assert.assertEquals(StateMachineTest.States.STATE1,target1);
    StateMachineTest.States target2 = stateMachine.fireEvent(StateMachineTest.States.STATE1, StateMachineTest.Events.EVENT1, new Context("2"));
    Assert.assertEquals(StateMachineTest.States.STATE2,target2);
    StateMachineTest.States target3 = stateMachine.fireEvent(StateMachineTest.States.STATE1, StateMachineTest.Events.EVENT1, new Context("3"));
    Assert.assertEquals(StateMachineTest.States.STATE3,target3);
    }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant