=act,per additional test for onTransition behaviour when initialize() called

This commit is contained in:
Konrad Malawski 2015-07-10 00:13:07 +02:00
parent 36ac50e7d3
commit 5d746b40b1
5 changed files with 65 additions and 6 deletions

View file

@ -503,7 +503,9 @@ trait FSM[S, D, E] extends Actor with Listeners with ActorLogging {
/**
* Verify existence of initial state and setup timers. This should be the
* last call within the constructor, or [[akka.actor.Actor#preStart]] and
* [[akka.actor.Actor#postRestart]]
* [[akka.actor.Actor#postRestart]].
*
* An initial `currentState -> currentState` notification will be triggered by calling this method.
*
* @see [[#startWith]]
*/

View file

@ -678,7 +678,7 @@ abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(confi
persistentActor ! GetState
expectMsg(List("a-1", "a-2", "b-10", "b-11", "b-12", "c-10", "c-11", "c-12"))
}
"recover on command failure xoxo" in {
"recover on command failure" in {
val persistentActor = namedPersistentActor[Behavior3PersistentActor]
persistentActor ! Cmd("b")
persistentActor ! "boom"

View file

@ -223,6 +223,20 @@ abstract class PersistentFSMActorSpec(config: Config) extends PersistenceSpec(co
expectTerminated(recoveredFsmRef)
}
}
"not trigger onTransition for stay()" taggedAs TimingTest in {
val persistenceId = name
val probe = TestProbe()
val fsmRef = system.actorOf(SimpleTransitionFSMActor.props(persistenceId, probe.ref))
probe.expectMsg(3.seconds, "LookingAround -> LookingAround") // caused by initialize(), OK
fsmRef ! "goto(the same state)" // causes goto()
probe.expectMsg(3.seconds, "LookingAround -> LookingAround")
fsmRef ! "stay" // causes stay()
probe.expectNoMsg(3.seconds)
}
}
}
@ -281,6 +295,28 @@ object PersistentFSMActorSpec {
case class PurchaseWasMade(items: Seq[Item]) extends ReportEvent
case object ShoppingCardDiscarded extends ReportEvent
class SimpleTransitionFSMActor(_persistenceId: String, reportActor: ActorRef)(implicit val domainEventClassTag: ClassTag[DomainEvent]) extends PersistentFsmActor[UserState, ShoppingCart, DomainEvent] {
override val persistenceId = _persistenceId
startWith(LookingAround, EmptyShoppingCart)
when(LookingAround) {
case Event("stay", _) stay
case Event(e, _) goto(LookingAround)
}
onTransition {
case (from, to) reportActor ! s"$from -> $to"
}
override def applyEvent(domainEvent: DomainEvent, currentData: ShoppingCart): ShoppingCart =
currentData
}
object SimpleTransitionFSMActor {
def props(persistenceId: String, reportActor: ActorRef) =
Props(new SimpleTransitionFSMActor(persistenceId, reportActor))
}
class WebStoreCustomerFSMActor(_persistenceId: String, reportActor: ActorRef)(implicit val domainEventClassTag: ClassTag[DomainEvent]) extends PersistentFsmActor[UserState, ShoppingCart, DomainEvent] {
override def persistenceId = _persistenceId