public void PersistentFSM_must_recover_successfully_with_correct_state_timeout() { var dummyReportActorRef = CreateTestProbe().Ref; var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); Watch(fsmRef); fsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); var shirt = new Item("1", "Shirt", 59.99F); fsmRef.Tell(new AddItem(shirt)); var userState1 = ExpectMsg <CurrentState <IUserState> >(); userState1.FsmRef.Should().Be(fsmRef); userState1.State.Should().Be(LookingAround.Instance); var transition1 = ExpectMsg <Transition <IUserState> >(); transition1.FsmRef.Should().Be(fsmRef); transition1.From.Should().Be(LookingAround.Instance); transition1.To.Should().Be(Shopping.Instance); ExpectNoMsg(TimeSpan.FromSeconds(0.6)); // arbitrarily chosen delay, less than the timeout, before stopping the FSM fsmRef.Tell(PoisonPill.Instance); ExpectTerminated(fsmRef); var recoveredFsmRef = Sys.ActorOf(Props.Create(() => new WebStoreCustomerFSM(Name, dummyReportActorRef))); Watch(recoveredFsmRef); recoveredFsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); var userState2 = ExpectMsg <CurrentState <IUserState> >(); userState2.FsmRef.Should().Be(recoveredFsmRef); userState2.State.Should().Be(Shopping.Instance); Within(TimeSpan.FromSeconds(0.9), RemainingOrDefault, () => { var transition2 = ExpectMsg <Transition <IUserState> >(); transition2.FsmRef.Should().Be(recoveredFsmRef); transition2.From.Should().Be(Shopping.Instance); transition2.To.Should().Be(Inactive.Instance); }); ExpectNoMsg(TimeSpan.FromSeconds(0.6)); // arbitrarily chosen delay, less than the timeout, before stopping the FSM recoveredFsmRef.Tell(PoisonPill.Instance); ExpectTerminated(recoveredFsmRef); var recoveredFsmRef2 = Sys.ActorOf(Props.Create(() => new WebStoreCustomerFSM(Name, dummyReportActorRef))); Watch(recoveredFsmRef2); recoveredFsmRef2.Tell(new SubscribeTransitionCallBack(TestActor)); var userState3 = ExpectMsg <CurrentState <IUserState> >(); userState3.FsmRef.Should().Be(recoveredFsmRef2); userState3.State.Should().Be(Inactive.Instance); ExpectTerminated(recoveredFsmRef2); }
public void PersistentFSM_must_has_function_as_regular_fsm_on_state_timeout() { var dummyReportActorRef = CreateTestProbe().Ref; var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); Watch(fsmRef); fsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); var shirt = new Item("1", "Shirt", 59.99F); fsmRef.Tell(new AddItem(shirt)); var userState = ExpectMsg <CurrentState <IUserState> >(); userState.FsmRef.Should().Be(fsmRef); userState.State.Should().Be(LookingAround.Instance); var transition1 = ExpectMsg <Transition <IUserState> >(); transition1.FsmRef.Should().Be(fsmRef); transition1.From.Should().Be(LookingAround.Instance); transition1.To.Should().Be(Shopping.Instance); Within(TimeSpan.FromSeconds(0.9), RemainingOrDefault, () => { var transition2 = ExpectMsg <Transition <IUserState> >(); transition2.FsmRef.Should().Be(fsmRef); transition2.From.Should().Be(Shopping.Instance); transition2.To.Should().Be(Inactive.Instance); }); ExpectTerminated(fsmRef); }
public void PersistentFSM_must_execute_the_defined_actions_following_successful_persistence_of_FSM_stop() { var reportActorProbe = CreateTestProbe(Sys); var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, reportActorProbe.Ref)); Watch(fsmRef); fsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); var shirt = new Item("1", "Shirt", 59.99F); var shoes = new Item("2", "Shoes", 89.99F); var coat = new Item("3", "Coat", 119.99F); fsmRef.Tell(new AddItem(shirt)); fsmRef.Tell(new AddItem(shoes)); fsmRef.Tell(new AddItem(coat)); fsmRef.Tell(new Leave()); var userState = ExpectMsg <CurrentState <IUserState> >(); userState.FsmRef.Should().Be(fsmRef); userState.State.Should().Be(LookingAround.Instance); var transition = ExpectMsg <Transition <IUserState> >(); transition.FsmRef.Should().Be(fsmRef); transition.From.Should().Be(LookingAround.Instance); transition.To.Should().Be(Shopping.Instance); reportActorProbe.ExpectMsg <ShoppingCardDiscarded>(); ExpectTerminated(fsmRef); }
public void PersistentFSM_must_persist_snapshot() { var dummyReportActorRef = CreateTestProbe().Ref; var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); Watch(fsmRef); var shirt = new Item("1", "Shirt", 59.99F); var shoes = new Item("2", "Shoes", 89.99F); var coat = new Item("3", "Coat", 119.99F); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shirt)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shoes)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(coat)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new Buy()); fsmRef.Tell(new GetCurrentCart()); ExpectMsg <EmptyShoppingCart>(); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); ExpectNoMsg(1.Seconds()); fsmRef.Tell(PoisonPill.Instance); ExpectTerminated(fsmRef); var recoveredFsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); recoveredFsmRef.Tell(new GetCurrentCart()); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); Watch(recoveredFsmRef); recoveredFsmRef.Tell(PoisonPill.Instance); ExpectTerminated(recoveredFsmRef); var persistentEventsStreamer = Sys.ActorOf(PersistentEventsStreamer.Props(Name, TestActor)); ExpectMsg <SnapshotOffer>(); Watch(persistentEventsStreamer); persistentEventsStreamer.Tell(PoisonPill.Instance); ExpectTerminated(persistentEventsStreamer); }
public void PersistentFSM_must_has_function_as_regular_fsm() { var dummyReportActorRef = CreateTestProbe().Ref; var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); Watch(fsmRef); fsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); var shirt = new Item("1", "Shirt", 59.99F); var shoes = new Item("2", "Shoes", 89.99F); var coat = new Item("3", "Coat", 119.99F); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shirt)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shoes)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(coat)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new Buy()); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new Leave()); var userState = ExpectMsg <CurrentState <IUserState> >(); userState.FsmRef.Should().Be(fsmRef); userState.State.Should().Be(LookingAround.Instance); ExpectMsg <EmptyShoppingCart>(); var transition1 = ExpectMsg <Transition <IUserState> >(); transition1.FsmRef.Should().Be(fsmRef); transition1.From.Should().Be(LookingAround.Instance); transition1.To.Should().Be(Shopping.Instance); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); var transition2 = ExpectMsg <Transition <IUserState> >(); transition2.FsmRef.Should().Be(fsmRef); transition2.From.Should().Be(Shopping.Instance); transition2.To.Should().Be(Paid.Instance); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); ExpectTerminated(fsmRef); }
public void PersistentFSM_must_not_persist_state_change_event_when_staying_in_the_same_state() { var dummyReportActorRef = CreateTestProbe().Ref; var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); Watch(fsmRef); var shirt = new Item("1", "Shirt", 59.99F); var shoes = new Item("2", "Shoes", 89.99F); var coat = new Item("3", "Coat", 119.99F); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shirt)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shoes)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(coat)); fsmRef.Tell(new GetCurrentCart()); ExpectMsg <EmptyShoppingCart>(); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); fsmRef.Tell(PoisonPill.Instance); ExpectTerminated(fsmRef); var persistentEventsStreamer = Sys.ActorOf(PersistentEventsStreamer.Props(Name, TestActor)); ExpectMsg <ItemAdded>().Item.Should().Be(shirt); ExpectMsg <PersistentFSM.StateChangeEvent>(); ExpectMsg <ItemAdded>().Item.Should().Be(shoes); ExpectMsg <PersistentFSM.StateChangeEvent>(); ExpectMsg <ItemAdded>().Item.Should().Be(coat); ExpectMsg <PersistentFSM.StateChangeEvent>(); Watch(persistentEventsStreamer); persistentEventsStreamer.Tell(PoisonPill.Instance); ExpectTerminated(persistentEventsStreamer); }
public void PersistentFSM_must_recover_successfully_with_correct_state_data() { var dummyReportActorRef = CreateTestProbe().Ref; var fsmRef = Sys.ActorOf(WebStoreCustomerFSM.Props(Name, dummyReportActorRef)); Watch(fsmRef); fsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); var shirt = new Item("1", "Shirt", 59.99F); var shoes = new Item("2", "Shoes", 89.99F); var coat = new Item("3", "Coat", 119.99F); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shirt)); fsmRef.Tell(new GetCurrentCart()); fsmRef.Tell(new AddItem(shoes)); fsmRef.Tell(new GetCurrentCart()); var userState1 = ExpectMsg <CurrentState <IUserState> >(); userState1.FsmRef.Should().Be(fsmRef); userState1.State.Should().Be(LookingAround.Instance); ExpectMsg <EmptyShoppingCart>(); var transition1 = ExpectMsg <Transition <IUserState> >(); transition1.FsmRef.Should().Be(fsmRef); transition1.From.Should().Be(LookingAround.Instance); transition1.To.Should().Be(Shopping.Instance); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes); fsmRef.Tell(PoisonPill.Instance); ExpectTerminated(fsmRef); var recoveredFsmRef = Sys.ActorOf(Props.Create(() => new WebStoreCustomerFSM(Name, dummyReportActorRef))); Watch(recoveredFsmRef); recoveredFsmRef.Tell(new SubscribeTransitionCallBack(TestActor)); recoveredFsmRef.Tell(new GetCurrentCart()); recoveredFsmRef.Tell(new AddItem(coat)); recoveredFsmRef.Tell(new GetCurrentCart()); recoveredFsmRef.Tell(new Buy()); recoveredFsmRef.Tell(new GetCurrentCart()); recoveredFsmRef.Tell(new Leave()); var userState2 = ExpectMsg <CurrentState <IUserState> >(); userState2.FsmRef.Should().Be(recoveredFsmRef); userState2.State.Should().Be(Shopping.Instance); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); var transition2 = ExpectMsg <Transition <IUserState> >(); transition2.FsmRef.Should().Be(recoveredFsmRef); transition2.From.Should().Be(Shopping.Instance); transition2.To.Should().Be(Paid.Instance); ExpectMsg <NonEmptyShoppingCart>().Items.Should().ContainInOrder(shirt, shoes, coat); ExpectTerminated(recoveredFsmRef); }