Skip to content
Snippets Groups Projects
Commit e3150e92 authored by Perry's avatar Perry Committed by Rodric Rabbah
Browse files

Generalize queryMap to activationMap.

Start consolidating map creation so no external ordering can cause internal race.
Consolidate loadbalancer API so that publishing a result and implicit querying of activation result.
Get rid of performLoadBalanceRequest by isolating behavior to test file.
Make sure consumer side is also protected in test mode.
Restore active ack timeout at 30 seconds.
Make a thin load balancer trait and remove unitTest flag.
Update some javadoc.
Removed queryActivationResponse (dead code).
parent 14b8958c
No related branches found
No related tags found
No related merge requests found
......@@ -648,7 +648,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
try {
// do not store the activation in the db, instead register it as the response to generate on active ack
whiskActivationStub = Some(activation)
loadBalancer.whiskActivationStub = Some(activation)
Post(s"$collectionPath/${action.name}?blocking=true") ~> sealRoute(routes(creds)) ~> check {
status should be(OK)
......@@ -663,7 +663,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
response should be(activation.resultAsJson)
}
} finally {
whiskActivationStub = None
loadBalancer.whiskActivationStub = None
}
}
......
......@@ -16,9 +16,8 @@
package whisk.core.controller.test
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ Await, Future }
import scala.concurrent.duration.{ DurationInt, FiniteDuration }
import scala.language.postfixOps
import org.scalatest.BeforeAndAfter
......@@ -26,38 +25,19 @@ import org.scalatest.BeforeAndAfterAll
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import akka.event.Logging.InfoLevel
import akka.event.Logging.{ InfoLevel, LogLevel }
import spray.http.BasicHttpCredentials
import spray.routing.HttpService
import spray.testkit.ScalatestRouteTest
import whisk.common.Logging
import whisk.common.TransactionCounter
import whisk.common.TransactionId
import whisk.common.{ Logging, TransactionCounter, TransactionId }
import whisk.core.WhiskConfig
import whisk.core.connector.ActivationMessage
import whisk.core.controller.WhiskActionsApi
import whisk.core.controller.WhiskServices
import whisk.core.database.test.DbUtils
import whisk.core.entitlement.Collection
import whisk.core.entitlement.EntitlementService
import whisk.core.entitlement.LocalEntitlementService
import whisk.core.entity.ActivationId
import whisk.core.entity.ActivationId.ActivationIdGenerator
import whisk.core.entity.AuthKey
import whisk.core.entity.DocId
import whisk.core.entity.EntityName
import whisk.core.entity.Subject
import whisk.core.entity.WhiskAction
import whisk.core.entity.WhiskActivation
import whisk.core.entity.WhiskActivationStore
import whisk.core.entity.WhiskAuth
import whisk.core.entity.WhiskAuthStore
import whisk.core.entity.WhiskEntityStore
import whisk.core.entity.WhiskPackage
import whisk.core.entity.WhiskRule
import whisk.core.entity.WhiskTrigger
import whisk.core.loadBalancer.LoadBalancerService
import scala.concurrent.duration.FiniteDuration
import whisk.core.entitlement.{ Collection, EntitlementService, LocalEntitlementService }
import whisk.core.entity._
import whisk.core.loadBalancer.LoadBalancer
protected trait ControllerTestCommon
extends FlatSpec
......@@ -80,33 +60,21 @@ protected trait ControllerTestCommon
override val whiskConfig = new WhiskConfig(WhiskActionsApi.requiredProperties)
assert(whiskConfig.isValid)
val loadBalancer = new LoadBalancerService(whiskConfig, InfoLevel)
override val loadBalancer = new DegenerateLoadBalancerService(whiskConfig, InfoLevel)
override val entitlementService: EntitlementService = new LocalEntitlementService(whiskConfig, loadBalancer)
override val performLoadBalancerRequest = (msg: ActivationMessage, tid: TransactionId) => Future.successful {}
override val activationId = new ActivationIdGenerator() {
override val activationId = new ActivationId.ActivationIdGenerator() {
// need a static activation id to test activations api
private val fixedId = ActivationId()
override def make = fixedId
}
override val queryActivationResponse = (activationId: ActivationId, timeout: FiniteDuration, transid: TransactionId) => {
whiskActivationStub map {
activation => Future.successful(activation)
} getOrElse (Future.failed {
new IllegalArgumentException("Unit test does not need fast path")
})
}
override val consulServer = "???"
val entityStore = WhiskEntityStore.datastore(whiskConfig)
val activationStore = WhiskActivationStore.datastore(whiskConfig)
val authStore = WhiskAuthStore.datastore(whiskConfig)
// unit tests that need an activation via active ack/fast path should set this to value expected
protected var whiskActivationStub: Option[WhiskActivation] = None
def createTempCredentials(implicit transid: TransactionId) = {
val auth = WhiskAuth(Subject(), AuthKey())
put(authStore, auth)
......@@ -189,3 +157,19 @@ protected trait ControllerTestCommon
authStore.shutdown()
}
}
class DegenerateLoadBalancerService(config: WhiskConfig, verbosity: LogLevel)
extends LoadBalancer {
// unit tests that need an activation via active ack/fast path should set this to value expected
var whiskActivationStub: Option[WhiskActivation] = None
override def getUserActivationCounts: Map[String, Long] = Map()
override def publish(msg: ActivationMessage, timeout: FiniteDuration)(implicit transid: TransactionId): (Future[Unit], Future[WhiskActivation]) =
(Future.successful {},
whiskActivationStub map {
activation => Future.successful(activation)
} getOrElse Future.failed(new IllegalArgumentException("Unit test does not need fast path")))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment