A question about from "outside-to-child-transition"

29 views
Skip to first unread message

Alexey Morozov

unread,
Jul 28, 2014, 7:48:17 PM7/28/14
to squirrel-st...@googlegroups.com
Hi!

I got another question which is likely caused by my misunderstanding what is possible to do with hierarchical SMs and what is not. Is it legal to jump directly from a  particular state to another state's child? Should the call sequence be "straightforward" in this case or maybe some extra steps are expected?

I have prepared a test case which demonstrates my troubles regarding this question

Suppose we have the following state machine description:

public class HierarchicalStateMachineTest {

   
public enum HState {
        A
, D, E, E1
   
}
   
public enum HEvent {
        A2D
, D2E1
   
}

   
@States({
        @State(name="A", initialState=true),
       
@State(name="D", entryCallMethod="enterD", exitCallMethod="leftD"),
       
@State(name="E", entryCallMethod="enterE", exitCallMethod="leftE"),
       
@State(parent="E", name="E1", entryCallMethod="enterE1", exitCallMethod="leftE1"),
       
})
   
@Transitions({
        @Transit(from="A", to="D", on="A2D", callMethod="transitA2D"),
       
@Transit(from="D", to="E1", on="D2E1", callMethod="transitD2E1"),
       
@Transit(from="A", to="C", on="Finish", callMethod="transitA2C"),
       
})
   
static class HierachicalStateMachine extends AbstractStateMachine<HierachicalStateMachine, HState, HEvent, Integer> {
        ... methods definitions as in HierarchicalStateMachineTest from the Squirrel Test Suite
    }


    @Test
    public void testChildTransition() {
      stateMachine.start();
      stateMachine.consumeLog();
      stateMachine.fire(HEvent.A2D, 1);
      stateMachine.consumeLog();
      stateMachine.fire(HEvent.D2E1, 2);
      assertThat(stateMachine.consumeLog(), is(equalTo("leftD.transitD2E1.enterE.enterE1")));
      assertThat(stateMachine.getCurrentState(), is(equalTo(HState.E1)));
    }

The test fails. The actual call sequence in this case happens to be the following: "leftD.enterD.leftD.transitD2E1.enterE.enterE1". As one may see, one extra `enterD` and `leftD` happen, quite unexpectedly for me. I'm still not sure if this is a problem of the test (that is somewhere in the state machine definition) or the problem in the state machine processor.

I've have attached the complete test as a patch to the HierarchicalStateMachineTest.java from current master.

Thanks,
Alexey

0001-From-other-to-child-failure-testcase.patch

Alexey Morozov

unread,
Jul 28, 2014, 10:20:16 PM7/28/14
to squirrel-st...@googlegroups.com
What's more intriguing is that introduction of an otherwise unneeded child state D1 and jumping from D1 to E1 solves the problem completely. The resulting sequence is 'leftD1.leftD.transitD12E1.enterE.enterE1'.

He Henry

unread,
Jul 30, 2014, 6:42:51 AM7/30/14
to squirrel-st...@googlegroups.com
Hi,

I think your expectation is correct. It is probably a bug. I will fixed later.

Thanks,
Henry

在 2014年7月29日星期二UTC+8上午7时48分17秒,Alexey Morozov写道:

He Henry

unread,
Jul 31, 2014, 6:19:48 AM7/31/14
to squirrel-st...@googlegroups.com
Fixed in latest snapshot version.

Alexey Morozov

unread,
Aug 1, 2014, 1:03:40 AM8/1/14
to squirrel-st...@googlegroups.com
Thank you so much!

31.07.2014 17:19, He Henry writes:
> Fixed in latest snapshot version.
>

Reply all
Reply to author
Forward
0 new messages