2012-01-19 14:38:44 +00:00
|
|
|
package akka.camel.internal
|
|
|
|
|
|
2012-06-25 18:28:38 +02:00
|
|
|
import language.postfixOps
|
2013-12-17 14:25:56 +01:00
|
|
|
import org.scalatest.Matchers
|
2012-09-21 14:50:06 +02:00
|
|
|
import scala.concurrent.duration._
|
2013-08-19 12:06:17 +02:00
|
|
|
import org.scalatest.{ GivenWhenThen, BeforeAndAfterEach, BeforeAndAfterAll, WordSpecLike }
|
2012-01-19 14:38:44 +00:00
|
|
|
import akka.actor.{ Props, ActorSystem }
|
2012-03-18 10:46:08 +01:00
|
|
|
import akka.camel._
|
2012-05-02 14:43:45 +02:00
|
|
|
import akka.testkit.{ TimingTest, TestProbe, TestKit }
|
2012-09-03 12:08:46 +02:00
|
|
|
import akka.camel.internal.ActivationProtocol._
|
2012-05-02 14:43:45 +02:00
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
class ActivationTrackerTest extends TestKit(ActorSystem("test")) with WordSpecLike with Matchers with BeforeAndAfterAll with BeforeAndAfterEach with GivenWhenThen {
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2014-01-17 23:08:32 +01:00
|
|
|
override protected def afterAll() { shutdown() }
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
var actor: TestProbe = _
|
|
|
|
|
var awaiting: Awaiting = _
|
|
|
|
|
var anotherAwaiting: Awaiting = _
|
|
|
|
|
val cause = new Exception("cause of failure")
|
|
|
|
|
|
|
|
|
|
override protected def beforeEach() {
|
|
|
|
|
actor = TestProbe()
|
|
|
|
|
awaiting = new Awaiting(actor)
|
|
|
|
|
anotherAwaiting = new Awaiting(actor)
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 12:08:46 +02:00
|
|
|
val at = system.actorOf(Props[ActivationTracker], name = "activationTrackker")
|
2012-09-26 02:20:12 +02:00
|
|
|
"ActivationTracker" must {
|
|
|
|
|
def publish(msg: Any) = at ! msg
|
|
|
|
|
implicit def timeout = remaining
|
|
|
|
|
"forwards activation message to all awaiting parties" taggedAs TimingTest in {
|
|
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
anotherAwaiting.awaitActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
publish(EndpointActivated(actor.ref))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
anotherAwaiting.verifyActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"send activation message even if activation happened earlier" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
Thread.sleep(50)
|
|
|
|
|
awaiting.awaitActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"send activation message even if actor is already deactivated" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
|
|
|
|
Thread.sleep(50)
|
|
|
|
|
awaiting.awaitActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"forward de-activation message to all awaiting parties" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.awaitDeActivation()
|
|
|
|
|
anotherAwaiting.awaitDeActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyDeActivated()
|
|
|
|
|
anotherAwaiting.verifyDeActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"forward de-activation message even if deactivation happened earlier" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.awaitDeActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
publish(EndpointDeActivated(actor.ref))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyDeActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"forward de-activation message even if someone awaits de-activation even before activation happens" taggedAs TimingTest in {
|
|
|
|
|
val awaiting = new Awaiting(actor)
|
|
|
|
|
awaiting.awaitDeActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
publish(EndpointActivated(actor.ref))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
publish(EndpointDeActivated(actor.ref))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyDeActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"send activation failure when failed to activate" taggedAs TimingTest in {
|
|
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
publish(EndpointFailedToActivate(actor.ref, cause))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyFailedToActivate()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"send de-activation failure when failed to de-activate" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
awaiting.awaitDeActivation()
|
|
|
|
|
publish(EndpointFailedToDeActivate(actor.ref, cause))
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyFailedToDeActivate()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
"send activation message even if it failed to de-activate" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointFailedToDeActivate(actor.ref, cause))
|
|
|
|
|
awaiting.awaitActivation()
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
2012-11-24 18:08:34 +01:00
|
|
|
|
|
|
|
|
"send activation message when an actor is activated, deactivated and activated again" taggedAs TimingTest in {
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Awaiting(actor: TestProbe) {
|
|
|
|
|
val probe = TestProbe()
|
|
|
|
|
def awaitActivation() = at.tell(AwaitActivation(actor.ref), probe.ref)
|
|
|
|
|
def awaitDeActivation() = at.tell(AwaitDeActivation(actor.ref), probe.ref)
|
2012-09-26 02:20:12 +02:00
|
|
|
def verifyActivated()(implicit timeout: FiniteDuration) = within(timeout) { probe.expectMsg(EndpointActivated(actor.ref)) }
|
|
|
|
|
def verifyDeActivated()(implicit timeout: FiniteDuration) = within(timeout) { probe.expectMsg(EndpointDeActivated(actor.ref)) }
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-09-26 02:20:12 +02:00
|
|
|
def verifyFailedToActivate()(implicit timeout: FiniteDuration) = within(timeout) { probe.expectMsg(EndpointFailedToActivate(actor.ref, cause)) }
|
|
|
|
|
def verifyFailedToDeActivate()(implicit timeout: FiniteDuration) = within(timeout) { probe.expectMsg(EndpointFailedToDeActivate(actor.ref, cause)) }
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|