private VNodeFSM CreateFSM() { var outputBus = new InMemoryBus("a", false); var state = VNodeState.Master; var stm = new VNodeFSMBuilder(() => state) .InAnyState() .When <SystemMessage.StateChangeMessage>().Do(m => { }) .InState(VNodeState.Initializing) .When <SystemMessage.SystemInit>().Do(msg => { }) .When <SystemMessage.SystemStart>().Do(msg => { }) .When <SystemMessage.BecomePreMaster>().Do(msg => { }) .When <SystemMessage.ServiceInitialized>().Do(msg => { }) .WhenOther().ForwardTo(outputBus) .InStates(VNodeState.Initializing, VNodeState.ShuttingDown, VNodeState.Shutdown) .When <ClientMessage.ReadRequestMessage>().Do(msg => { }) .InAllStatesExcept(VNodeState.Initializing, VNodeState.ShuttingDown, VNodeState.Shutdown) .When <ClientMessage.ReadRequestMessage>().ForwardTo(outputBus) .InAllStatesExcept(VNodeState.PreMaster) .When <SystemMessage.WaitForChaserToCatchUp>().Ignore() .When <SystemMessage.ChaserCaughtUp>().Ignore() .InState(VNodeState.PreMaster) .When <SystemMessage.BecomeMaster>().Do(msg => { }) .When <SystemMessage.WaitForChaserToCatchUp>().ForwardTo(outputBus) .When <SystemMessage.ChaserCaughtUp>().Do(msg => { }) .WhenOther().ForwardTo(outputBus) .InState(VNodeState.Master) .When <ClientMessage.WriteEvents>().Do(msg => { }) .When <ClientMessage.TransactionStart>().Do(msg => { }) .When <ClientMessage.TransactionWrite>().Do(msg => { }) .When <ClientMessage.TransactionCommit>().Do(msg => { }) .When <ClientMessage.DeleteStream>().Do(msg => { }) .When <StorageMessage.WritePrepares>().ForwardTo(outputBus) .When <StorageMessage.WriteDelete>().ForwardTo(outputBus) .When <StorageMessage.WriteTransactionStart>().ForwardTo(outputBus) .When <StorageMessage.WriteTransactionData>().ForwardTo(outputBus) .When <StorageMessage.WriteTransactionPrepare>().ForwardTo(outputBus) .When <StorageMessage.WriteCommit>().ForwardTo(outputBus) .WhenOther().ForwardTo(outputBus) .InAllStatesExcept(VNodeState.Master) .When <ClientMessage.WriteRequestMessage>().Do(msg => { }) .When <StorageMessage.WritePrepares>().Ignore() .When <StorageMessage.WriteDelete>().Ignore() .When <StorageMessage.WriteTransactionStart>().Ignore() .When <StorageMessage.WriteTransactionData>().Ignore() .When <StorageMessage.WriteTransactionPrepare>().Ignore() .When <StorageMessage.WriteCommit>().Ignore() .InAllStatesExcept(VNodeState.ShuttingDown, VNodeState.Shutdown) .When <ClientMessage.RequestShutdown>().Do(msg => { }) .When <SystemMessage.BecomeShuttingDown>().Do(msg => { }) .InState(VNodeState.ShuttingDown) .When <SystemMessage.BecomeShutdown>().Do(msg => { }) .When <SystemMessage.ShutdownTimeout>().Do(msg => { }) .InStates(VNodeState.ShuttingDown, VNodeState.Shutdown) .When <SystemMessage.ServiceShutdown>().Do(msg => { }) .WhenOther().ForwardTo(outputBus) .Build(); return(stm); }
public void allow_ignoring_messages_by_common_ancestor() { var fsm = new VNodeFSMBuilder(() => VNodeState.Master) .InAnyState() .When <P>().Ignore() .WhenOther().Do(x => Assert.Fail("{0} slipped through", x.GetType().Name)) .Build(); fsm.Handle(new A()); fsm.Handle(new B()); }
public void allow_ignoring_messages_by_common_ancestor() { var fsm = new VNodeFSMBuilder(() => VNodeState.Master) .InAnyState() .When<P>().Ignore() .WhenOther().Do(x => Assert.Fail("{0} slipped through", x.GetType().Name)) .Build(); fsm.Handle(new A()); fsm.Handle(new B()); }
public void handle_specific_message_even_if_base_message_is_ignored() { bool aHandled = false; var fsm = new VNodeFSMBuilder(() => VNodeState.Master) .InAnyState() .When <P>().Ignore() .When <A>().Do(x => aHandled = true) .WhenOther().Do(x => Assert.Fail("{0} slipped through", x.GetType().Name)) .Build(); fsm.Handle(new A()); fsm.Handle(new B()); Assert.IsTrue(aHandled); }
public void handle_specific_message_even_if_base_message_is_ignored() { bool aHandled = false; var fsm = new VNodeFSMBuilder(() => VNodeState.Master) .InAnyState() .When<P>().Ignore() .When<A>().Do(x => aHandled = true) .WhenOther().Do(x => Assert.Fail("{0} slipped through", x.GetType().Name)) .Build(); fsm.Handle(new A()); fsm.Handle(new B()); Assert.IsTrue(aHandled); }
private VNodeFSM CreateFSM() { var stm = new VNodeFSMBuilder(() => _state).InAnyState() .When <SystemMessage.StateChangeMessage>() .Do( m => Application.Exit( ExitCode.Error, string.Format( "{0} message was unhandled in {1}.", m.GetType().Name, GetType().Name))) .InState(VNodeState.Initializing) .When <SystemMessage.SystemInit>() .Do(Handle) .When <SystemMessage.SystemStart>() .Do(Handle) .When <SystemMessage.BecomePreMaster>() .Do(Handle) .When <SystemMessage.ServiceInitialized>() .Do(Handle) .WhenOther() .ForwardTo(_outputBus) .InStates( VNodeState.Initializing, VNodeState.ShuttingDown, VNodeState.Shutdown) .When <ClientMessage.ReadRequestMessage>() .Do(msg => DenyRequestBecauseNotReady(msg.Envelope, msg.CorrelationId)) .InAllStatesExcept( VNodeState.Initializing, VNodeState.ShuttingDown, VNodeState.Shutdown) .When <ClientMessage.ReadRequestMessage>() .ForwardTo(_outputBus) .InAllStatesExcept(VNodeState.PreMaster) .When <SystemMessage.WaitForChaserToCatchUp>() .Ignore() .When <SystemMessage.ChaserCaughtUp>() .Ignore() .InState(VNodeState.PreMaster) .When <SystemMessage.BecomeMaster>() .Do(Handle) .When <SystemMessage.WaitForChaserToCatchUp>() .ForwardTo(_outputBus) .When <SystemMessage.ChaserCaughtUp>() .Do(Handle) .WhenOther() .ForwardTo(_outputBus) .InState(VNodeState.Master) .When <ClientMessage.WriteEvents>() .Do(Handle) .When <ClientMessage.TransactionStart>() .Do(Handle) .When <ClientMessage.TransactionWrite>() .Do(Handle) .When <ClientMessage.TransactionCommit>() .Do(Handle) .When <ClientMessage.DeleteStream>() .Do(Handle) .When <StorageMessage.WritePrepares>() .ForwardTo(_outputBus) .When <StorageMessage.WriteDelete>() .ForwardTo(_outputBus) .When <StorageMessage.WriteTransactionStart>() .ForwardTo(_outputBus) .When <StorageMessage.WriteTransactionData>() .ForwardTo(_outputBus) .When <StorageMessage.WriteTransactionPrepare>() .ForwardTo(_outputBus) .When <StorageMessage.WriteCommit>() .ForwardTo(_outputBus) .WhenOther() .ForwardTo(_outputBus) .InAllStatesExcept(VNodeState.Master) .When <ClientMessage.WriteRequestMessage>() .Do(msg => DenyRequestBecauseNotReady(msg.Envelope, msg.CorrelationId)) .When <StorageMessage.WritePrepares>() .Ignore() .When <StorageMessage.WriteDelete>() .Ignore() .When <StorageMessage.WriteTransactionStart>() .Ignore() .When <StorageMessage.WriteTransactionData>() .Ignore() .When <StorageMessage.WriteTransactionPrepare>() .Ignore() .When <StorageMessage.WriteCommit>() .Ignore() .InAllStatesExcept(VNodeState.ShuttingDown, VNodeState.Shutdown) .When <ClientMessage.RequestShutdown>() .Do(Handle) .When <SystemMessage.BecomeShuttingDown>() .Do(Handle) .InState(VNodeState.ShuttingDown) .When <SystemMessage.BecomeShutdown>() .Do(Handle) .When <SystemMessage.ShutdownTimeout>() .Do(Handle) .InStates(VNodeState.ShuttingDown, VNodeState.Shutdown) .When <SystemMessage.ServiceShutdown>() .Do(Handle) .WhenOther() .ForwardTo(_outputBus) .Build(); return(stm); }
private VNodeFSM CreateFSM() { var outputBus = new InMemoryBus("a", false); var state = VNodeState.Master; var stm = new VNodeFSMBuilder(() => state) .InAnyState() .When<SystemMessage.StateChangeMessage>().Do(m => { }) .InState(VNodeState.Initializing) .When<SystemMessage.SystemInit>().Do(msg => { }) .When<SystemMessage.SystemStart>().Do(msg => { }) .When<SystemMessage.BecomePreMaster>().Do(msg => { }) .When<SystemMessage.StorageReaderInitializationDone>().Do(msg => { }) .When<SystemMessage.StorageWriterInitializationDone>().Do(msg => { }) .WhenOther().ForwardTo(outputBus) .InStates(VNodeState.Initializing, VNodeState.ShuttingDown, VNodeState.Shutdown) .When<ClientMessage.ReadRequestMessage>().Do(msg => { }) .InAllStatesExcept(VNodeState.Initializing, VNodeState.ShuttingDown, VNodeState.Shutdown) .When<ClientMessage.ReadRequestMessage>().ForwardTo(outputBus) .InAllStatesExcept(VNodeState.PreMaster) .When<SystemMessage.WaitForChaserToCatchUp>().Ignore() .When<SystemMessage.ChaserCaughtUp>().Ignore() .InState(VNodeState.PreMaster) .When<SystemMessage.BecomeMaster>().Do(msg => { }) .When<SystemMessage.WaitForChaserToCatchUp>().ForwardTo(outputBus) .When<SystemMessage.ChaserCaughtUp>().Do(msg => { }) .WhenOther().ForwardTo(outputBus) .InState(VNodeState.Master) .When<ClientMessage.WriteEvents>().Do(msg => { }) .When<ClientMessage.TransactionStart>().Do(msg => { }) .When<ClientMessage.TransactionWrite>().Do(msg => { }) .When<ClientMessage.TransactionCommit>().Do(msg => { }) .When<ClientMessage.DeleteStream>().Do(msg => { }) .When<StorageMessage.WritePrepares>().ForwardTo(outputBus) .When<StorageMessage.WriteDelete>().ForwardTo(outputBus) .When<StorageMessage.WriteTransactionStart>().ForwardTo(outputBus) .When<StorageMessage.WriteTransactionData>().ForwardTo(outputBus) .When<StorageMessage.WriteTransactionPrepare>().ForwardTo(outputBus) .When<StorageMessage.WriteCommit>().ForwardTo(outputBus) .WhenOther().ForwardTo(outputBus) .InAllStatesExcept(VNodeState.Master) .When<ClientMessage.WriteRequestMessage>().Do(msg => { }) .When<StorageMessage.WritePrepares>().Ignore() .When<StorageMessage.WriteDelete>().Ignore() .When<StorageMessage.WriteTransactionStart>().Ignore() .When<StorageMessage.WriteTransactionData>().Ignore() .When<StorageMessage.WriteTransactionPrepare>().Ignore() .When<StorageMessage.WriteCommit>().Ignore() .InAllStatesExcept(VNodeState.ShuttingDown, VNodeState.Shutdown) .When<ClientMessage.RequestShutdown>().Do(msg => { }) .When<SystemMessage.BecomeShuttingDown>().Do(msg => { }) .InState(VNodeState.ShuttingDown) .When<SystemMessage.BecomeShutdown>().Do(msg => { }) .When<SystemMessage.ShutdownTimeout>().Do(msg => { }) .InStates(VNodeState.ShuttingDown, VNodeState.Shutdown) .When<SystemMessage.ServiceShutdown>().Do(msg => { }) .WhenOther().ForwardTo(outputBus) .Build(); return stm; }