#2717 - Fixing the backoff strategy in PojoSRTestSupport
This commit is contained in:
parent
1d768fa10c
commit
975bd1dbe9
1 changed files with 13 additions and 7 deletions
|
|
@ -10,13 +10,14 @@ import org.apache.commons.io.IOUtils.copy
|
|||
|
||||
import org.osgi.framework._
|
||||
import java.net.URL
|
||||
|
||||
import java.util.jar.JarInputStream
|
||||
import java.io._
|
||||
import org.scalatest.{ BeforeAndAfterAll, Suite }
|
||||
import java.util.{ UUID, Date, ServiceLoader, HashMap }
|
||||
import scala.reflect.ClassTag
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.duration._
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/**
|
||||
* Trait that provides support for building akka-osgi tests using PojoSR
|
||||
|
|
@ -72,13 +73,18 @@ trait PojoSRTestSupport extends Suite with BeforeAndAfterAll {
|
|||
def awaitReference(serviceType: Class[_]): ServiceReference = awaitReference(serviceType, START_WAIT_TIME)
|
||||
|
||||
def awaitReference(serviceType: Class[_], wait: Long): ServiceReference = {
|
||||
val option = Option(context.getServiceReference(serviceType.getName))
|
||||
Thread.sleep(wait) //FIXME No sleep please
|
||||
option match {
|
||||
case Some(reference) ⇒ reference
|
||||
case None if (wait > MAX_WAIT_TIME) ⇒ fail("Gave up waiting for service of type %s".format(serviceType))
|
||||
case None ⇒ awaitReference(serviceType, wait * 2)
|
||||
|
||||
@tailrec def poll(step: Duration, deadline: Deadline): ServiceReference = context.getServiceReference(serviceType.getName) match {
|
||||
case null ⇒
|
||||
if (deadline.isOverdue()) fail("Gave up waiting for service of type %s".format(serviceType))
|
||||
else {
|
||||
Thread.sleep((step min deadline.timeLeft).toMillis)
|
||||
poll(step, deadline)
|
||||
}
|
||||
case some ⇒ some
|
||||
}
|
||||
|
||||
poll(wait.millis, Deadline.now + MAX_WAIT_TIME.millis)
|
||||
}
|
||||
|
||||
protected def buildTestBundles(builders: immutable.Seq[BundleDescriptorBuilder]): immutable.Seq[BundleDescriptor] =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue