pekko/akka-cluster/src/test/scala/akka/cluster/ClusterDeployerSpec.scala
Patrik Nordwall 84ade6fdc3 add CoordinatedShutdown, #21537
* CoordinatedShutdown that can run tasks for configured phases in order (DAG)
* coordinate handover/shutdown of singleton with cluster exiting/shutdown
* phase config obj with depends-on list
* integrate graceful leaving of sharding in coordinated shutdown
* add timeout and recover
* add some missing artery ports to tests
* leave via CoordinatedShutdown.run
* optionally exit-jvm in last phase
* run via jvm shutdown hook
* send ExitingConfirmed to leader before shutdown of Exiting
  to not have to wait for failure detector to mark it as
  unreachable before removing
* the unreachable signal is still kept as a safe guard if
  message is lost or leader dies
* PhaseClusterExiting vs MemberExited in ClusterSingletonManager
* terminate ActorSystem when cluster shutdown (via Down)
* add more predefined and custom phases
* reference documentation
* migration guide
* problem when the leader order was sys2, sys1, sys3,
  then sys3 could not perform it's duties and move Leving sys1 to
  Exiting because it was observing sys1 as unreachable
* exclude Leaving with exitingConfirmed from convergence condidtion
2017-01-16 09:01:57 +01:00

90 lines
3 KiB
Scala

/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package akka.cluster
import akka.testkit._
import akka.actor._
import akka.routing._
import com.typesafe.config._
import akka.cluster.routing.ClusterRouterPool
import akka.cluster.routing.ClusterRouterGroup
import akka.cluster.routing.ClusterRouterPoolSettings
import akka.cluster.routing.ClusterRouterGroupSettings
object ClusterDeployerSpec {
val deployerConf = ConfigFactory.parseString("""
akka.actor.provider = "cluster"
akka.actor.deployment {
/user/service1 {
router = round-robin-pool
cluster.enabled = on
cluster.max-nr-of-instances-per-node = 3
cluster.max-total-nr-of-instances = 20
cluster.allow-local-routees = off
}
/user/service2 {
dispatcher = mydispatcher
mailbox = mymailbox
router = round-robin-group
routees.paths = ["/user/myservice"]
cluster.enabled = on
cluster.max-total-nr-of-instances = 20
cluster.allow-local-routees = off
}
}
akka.remote.netty.tcp.port = 0
akka.remote.artery.canonical.port = 0
""", ConfigParseOptions.defaults)
class RecipeActor extends Actor {
def receive = { case _ }
}
}
class ClusterDeployerSpec extends AkkaSpec(ClusterDeployerSpec.deployerConf) {
"A RemoteDeployer" must {
"be able to parse 'akka.actor.deployment._' with specified cluster pool" in {
val service = "/user/service1"
val deployment = system.asInstanceOf[ActorSystemImpl].provider.deployer.lookup(service.split("/").drop(1))
deployment should not be (None)
deployment should ===(Some(
Deploy(
service,
deployment.get.config,
ClusterRouterPool(RoundRobinPool(20), ClusterRouterPoolSettings(
totalInstances = 20, maxInstancesPerNode = 3, allowLocalRoutees = false, useRole = None)),
ClusterScope,
Deploy.NoDispatcherGiven,
Deploy.NoMailboxGiven)))
}
"be able to parse 'akka.actor.deployment._' with specified cluster group" in {
val service = "/user/service2"
val deployment = system.asInstanceOf[ActorSystemImpl].provider.deployer.lookup(service.split("/").drop(1))
deployment should not be (None)
deployment should ===(Some(
Deploy(
service,
deployment.get.config,
ClusterRouterGroup(RoundRobinGroup(List("/user/myservice")), ClusterRouterGroupSettings(
totalInstances = 20, routeesPaths = List("/user/myservice"), allowLocalRoutees = false, useRole = None)),
ClusterScope,
"mydispatcher",
"mymailbox")))
}
"have correct router mappings" in {
val mapping = system.asInstanceOf[ActorSystemImpl].provider.deployer.routerTypeMapping
mapping("adaptive-pool") should ===(classOf[akka.cluster.routing.AdaptiveLoadBalancingPool].getName)
mapping("adaptive-group") should ===(classOf[akka.cluster.routing.AdaptiveLoadBalancingGroup].getName)
}
}
}