2012-05-29 12:41:09 +02:00
|
|
|
package akka.osgi
|
|
|
|
|
|
|
|
|
|
import org.scalatest.FlatSpec
|
2012-06-12 16:08:19 +02:00
|
|
|
import akka.actor.ActorSystem
|
2012-05-29 12:41:09 +02:00
|
|
|
import akka.pattern.ask
|
|
|
|
|
import akka.dispatch.Await
|
|
|
|
|
import akka.util.duration._
|
|
|
|
|
import akka.util.Timeout
|
2012-06-12 16:08:19 +02:00
|
|
|
import de.kalpatec.pojosr.framework.launch.BundleDescriptor
|
|
|
|
|
import test.TestActorSystemActivator
|
|
|
|
|
import test.PingPong._
|
|
|
|
|
import PojoSRTestSupport.bundle
|
2012-05-29 12:41:09 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test cases for {@link ActorSystemActivator}
|
|
|
|
|
*/
|
2012-06-12 16:08:19 +02:00
|
|
|
class ActorSystemActivatorTest extends FlatSpec with PojoSRTestSupport {
|
2012-05-29 12:41:09 +02:00
|
|
|
|
2012-06-12 16:08:19 +02:00
|
|
|
val TEST_BUNDLE_NAME = "akka.osgi.test.activator"
|
2012-05-29 12:41:09 +02:00
|
|
|
|
2012-06-12 16:08:19 +02:00
|
|
|
val testBundles: Seq[BundleDescriptor] = Seq(
|
|
|
|
|
bundle(TEST_BUNDLE_NAME).withActivator(classOf[TestActorSystemActivator]))
|
2012-05-29 12:41:09 +02:00
|
|
|
|
2012-06-12 16:08:19 +02:00
|
|
|
"ActorSystemActivator" should "start and register the ActorSystem when bundle starts" in {
|
|
|
|
|
val system = serviceForType[ActorSystem]
|
2012-05-29 12:41:09 +02:00
|
|
|
val actor = system.actorFor("/user/pong")
|
|
|
|
|
|
|
|
|
|
implicit val timeout = Timeout(5 seconds)
|
|
|
|
|
val future = actor ? Ping
|
|
|
|
|
val result = Await.result(future, timeout.duration)
|
|
|
|
|
assert(result != null)
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 16:08:19 +02:00
|
|
|
it should "stop the ActorSystem when bundle stops" in {
|
|
|
|
|
val system = serviceForType[ActorSystem]
|
2012-05-29 12:41:09 +02:00
|
|
|
assert(!system.isTerminated)
|
|
|
|
|
|
2012-06-12 16:08:19 +02:00
|
|
|
bundleForName(TEST_BUNDLE_NAME).stop()
|
2012-05-29 12:41:09 +02:00
|
|
|
|
|
|
|
|
system.awaitTermination()
|
|
|
|
|
assert(system.isTerminated)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|