blended.itestsupport.jms.JMSChecker.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.jms
import java.util.concurrent.atomic.AtomicBoolean
import javax.jms.ConnectionFactory
import akka.actor._
import akka.util.Timeout
import blended.itestsupport.condition.{AsyncChecker, AsyncCondition}
import blended.jms.utils.JMSSupport
import scala.concurrent.Future
import scala.concurrent.duration._
object JMSAvailableCondition{
def apply(cf: ConnectionFactory, t: Option[FiniteDuration] = None)(implicit system: ActorSystem) =
AsyncCondition(Props(JMSChecker(cf)), s"JMSAvailableCondition(${cf})", t)
}
private[jms] object JMSChecker {
def apply(cf: ConnectionFactory) = new JMSChecker(cf)
}
private[jms]class JMSChecker(cf: ConnectionFactory) extends AsyncChecker with JMSSupport {
var connected : AtomicBoolean = new AtomicBoolean(false)
var connecting : AtomicBoolean = new AtomicBoolean(false)
override def supervisorStrategy = OneForOneStrategy() {
case _ => SupervisorStrategy.Stop
}
override def performCheck(cond: AsyncCondition) : Future[Boolean] = {
implicit val t = Timeout(5.seconds)
log.debug(s"Checking JMS connection...[$cf]")
if ( (!connected.get()) && (!connecting.get()) ) {
connecting.set(true)
withConnection { _ =>
connected.set(true)
} (cf) foreach { t =>
log.debug(s"Error checking JMS connection : ${t.getMessage})")
}
connecting.set(false)
}
Future(connected.get())
}
}