Skip to content

Instantly share code, notes, and snippets.

@arosien
Created September 28, 2011 23:05
Show Gist options
  • Save arosien/1249511 to your computer and use it in GitHub Desktop.
Save arosien/1249511 to your computer and use it in GitHub Desktop.
wierd akka fsm matching problem
import org.specs2.mutable.Specification
import akka.actor.Actor
import akka.actor.FSM
import akka.testkit.TestFSMRef
import org.specs2.specification.Scope
class AkkaFSMEventSpec extends Specification {
case class A(msg: String)
case class B(msg: String)
class TestFSM extends Actor with FSM[Int, String] {
startWith(1, "foo")
when(1) { case Event(_, data) => stay() }
initialize
def event(message: Any) = Event(message, stateData)
def evThenEv: PartialFunction[Event, Any] = {
case Ev(A(msg)) => msg
case Ev(B(msg)) => msg
}
def eventThenEv: PartialFunction[Event, Any] = {
case Event(A(msg), data) => msg
case Ev(B(msg)) => msg
}
def evThenEvent: PartialFunction[Event, Any] = {
case Ev(B(msg)) => msg
case Event(A(msg), data) => msg
}
}
trait Fixture extends Scope {
val fsm = TestFSMRef(new TestFSM()).underlyingActor
}
"Akka FSM" should {
"match Ev then Ev" in new Fixture {
fsm.evThenEv(fsm.event(B("msg"))) must_== "msg"
}
"match Event then Ev" in new Fixture {
fsm.eventThenEv(fsm.event(B("msg"))) must_== "msg"
}
"match Ev then Event" in new Fixture {
fsm.evThenEvent(fsm.event(B("msg"))) must_== "msg"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment