2012-01-19 14:38:44 +00:00
|
|
|
package akka.camel.internal
|
|
|
|
|
|
2012-06-25 18:28:38 +02:00
|
|
|
import language.postfixOps
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.scalatest.matchers.MustMatchers
|
2012-06-29 13:33:20 +02:00
|
|
|
import scala.concurrent.util.duration._
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.scalatest.{ GivenWhenThen, BeforeAndAfterEach, BeforeAndAfterAll, WordSpec }
|
|
|
|
|
import akka.actor.{ Props, ActorSystem }
|
2012-06-29 13:33:20 +02:00
|
|
|
import scala.concurrent.util.Duration
|
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-01-19 14:38:44 +00:00
|
|
|
class ActivationTrackerTest extends TestKit(ActorSystem("test")) with WordSpec with MustMatchers with BeforeAndAfterAll with BeforeAndAfterEach with GivenWhenThen {
|
|
|
|
|
|
|
|
|
|
override protected def afterAll() { system.shutdown() }
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val at = system.actorOf(Props[ActivationTracker])
|
|
|
|
|
|
2012-05-02 14:43:45 +02:00
|
|
|
"ActivationTracker forwards activation message to all awaiting parties" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
anotherAwaiting.awaitActivation()
|
|
|
|
|
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
|
|
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
anotherAwaiting.verifyActivated()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker send activation message even if activation happened earlier" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
Thread.sleep(50)
|
|
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
|
|
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker send activation message even if actor is already deactivated" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
|
|
|
|
Thread.sleep(50)
|
|
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
|
|
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker forwards de-activation message to all awaiting parties" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
|
|
|
|
|
|
|
|
|
awaiting.awaitDeActivation()
|
|
|
|
|
anotherAwaiting.awaitDeActivation()
|
|
|
|
|
|
|
|
|
|
awaiting.verifyDeActivated()
|
|
|
|
|
anotherAwaiting.verifyDeActivated()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker forwards de-activation message even if deactivation happened earlier" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
|
|
|
|
|
awaiting.awaitDeActivation()
|
|
|
|
|
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
|
|
|
|
|
|
|
|
|
awaiting.verifyDeActivated()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker forwards de-activation message even if someone awaits de-activation even before activation happens" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
val awaiting = new Awaiting(actor)
|
|
|
|
|
awaiting.awaitDeActivation()
|
|
|
|
|
|
|
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
|
|
|
|
|
publish(EndpointDeActivated(actor.ref))
|
|
|
|
|
|
|
|
|
|
awaiting.verifyDeActivated()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker sends activation failure when failed to activate" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
publish(EndpointFailedToActivate(actor.ref, cause))
|
|
|
|
|
|
|
|
|
|
awaiting.verifyFailedToActivate()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker sends de-activation failure when failed to de-activate" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
awaiting.awaitDeActivation()
|
|
|
|
|
publish(EndpointFailedToDeActivate(actor.ref, cause))
|
|
|
|
|
|
|
|
|
|
awaiting.verifyFailedToDeActivate()
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-07 20:38:10 +02:00
|
|
|
"ActivationTracker sends activation message even if it failed to de-activate" taggedAs TimingTest in {
|
2012-01-19 14:38:44 +00:00
|
|
|
publish(EndpointActivated(actor.ref))
|
|
|
|
|
publish(EndpointFailedToDeActivate(actor.ref, cause))
|
|
|
|
|
awaiting.awaitActivation()
|
|
|
|
|
|
|
|
|
|
awaiting.verifyActivated()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def publish(msg: AnyRef) = system.eventStream.publish(msg)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
def verifyActivated(timeout: Duration = 50 millis) = within(timeout) { probe.expectMsg(EndpointActivated(actor.ref)) }
|
|
|
|
|
def verifyDeActivated(timeout: Duration = 50 millis) = within(timeout) { probe.expectMsg(EndpointDeActivated(actor.ref)) }
|
|
|
|
|
|
|
|
|
|
def verifyFailedToActivate(timeout: Duration = 50 millis) = within(timeout) { probe.expectMsg(EndpointFailedToActivate(actor.ref, cause)) }
|
|
|
|
|
def verifyFailedToDeActivate(timeout: Duration = 50 millis) = within(timeout) { probe.expectMsg(EndpointFailedToDeActivate(actor.ref, cause)) }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|