|
Play Framework/Scala example source code file (AkkaSpec.scala)
The AkkaSpec.scala Play Framework example source code
/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package play.api.libs.concurrent
import org.specs2.mutable._
import play.api.libs._
import play.api.FakeApplication
import akka.actor.{Props, Actor}
import java.util.Date
object AkkaSpec extends Specification {
// returns the time it took to stop the Akka plugin in milliseconds
def testBlockingActor(app: play.api.Application): Long = {
val plugin = new AkkaPlugin(app)
val blockingActor = plugin.applicationSystem.actorOf(Props[BlockingActor])
blockingActor ! Block
val startTime = System.nanoTime()
plugin.onStop()
val endTime = System.nanoTime()
(endTime - startTime) / 1000 / 1000
}
"AkkaPlugin with a blocking Actor" should {
"by default wait until the blocking actor is terminated" in {
val totalTime = testBlockingActor(FakeApplication())
// the actor blocks shutdown for 10 seconds
totalTime must be greaterThanOrEqualTo 10000
}
"be able to be restarted when the Actor is blocking if the config is provided" in {
val app = FakeApplication(Map("play.akka.shutdown-timeout" -> "500ms"))
val totalTime = testBlockingActor(app)
// the actor blocks for 10 seconds but we should be back here in around 500ms
totalTime must be between (500, 10000)
}
}
}
class BlockingActor extends Actor {
def receive = {
case Block =>
context.system.log.info("BlockingActor is now blocking for 10 seconds")
Thread.sleep(10000)
context.system.log.info("BlockingActor is done blocking")
}
}
case object Block
Other Play Framework source code examplesHere is a short list of links related to this Play Framework AkkaSpec.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.