blended.itestsupport.condition.AsyncChecker.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blended.itestsupport Show documentation
Show all versions of blended.itestsupport Show documentation
Define an integration test API for collaborating blended container(s) using docker as a runtime
for the container(s) under test and an Akka based Camel framework to perform the integration tests
as pure blackbox tests. Container(s) may be prestarted and discovered (for execution speed) or
started by the integration test (for reproducability).
The newest version!
package blended.itestsupport.condition
import akka.actor.{Actor, ActorLogging}
import blended.itestsupport.protocol.CheckAsyncCondition
import scala.concurrent.Future
abstract class AsyncChecker extends Actor with ActorLogging {
protected implicit val ctxt = context.system.dispatcher
case object Tick
case object Stop
def performCheck(condition: AsyncCondition) : Future[Boolean]
def receive = initializing
def initializing : Receive = {
case CheckAsyncCondition(condition) =>
log.debug("Starting asynchronous condition checker")
self ! Tick
context.become(checking(condition))
}
def checking(condition: AsyncCondition) : Receive = {
case Tick =>
log.debug(s"Checking asynchronous [${condition.description}] condition ....")
performCheck(condition).map(_ match {
case true =>
log.debug(s"Asynchronous condition [${condition.description}] is now satisfied.")
condition.isSatisfied.set(true)
context.stop(self)
case false =>
log.debug(s"Scheduling next condition check in [${condition.interval}]")
context.system.scheduler.scheduleOnce(condition.interval, self, Tick)
})
}
}