Merge pull request #23965 from danischroeter/shardingNamesTest
Provide access to known shard types add test #23912
This commit is contained in:
commit
ad7f68f994
1 changed files with 44 additions and 0 deletions
|
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||||
|
*/
|
||||||
|
package akka.cluster.sharding
|
||||||
|
|
||||||
|
import akka.actor.Props
|
||||||
|
import akka.cluster.Cluster
|
||||||
|
import akka.testkit.AkkaSpec
|
||||||
|
import akka.testkit.TestActors.EchoActor
|
||||||
|
|
||||||
|
object GetShardTypeNamesSpec {
|
||||||
|
val config =
|
||||||
|
"""
|
||||||
|
akka.loglevel = INFO
|
||||||
|
akka.actor.provider = "cluster"
|
||||||
|
"""
|
||||||
|
|
||||||
|
val extractEntityId: ShardRegion.ExtractEntityId = {
|
||||||
|
case msg: Int ⇒ (msg.toString, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
val extractShardId: ShardRegion.ExtractShardId = {
|
||||||
|
case msg: Int ⇒ (msg % 10).toString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetShardTypeNamesSpec extends AkkaSpec(GetShardTypeNamesSpec.config) {
|
||||||
|
import GetShardTypeNamesSpec._
|
||||||
|
|
||||||
|
"GetShardTypeNames" must {
|
||||||
|
"contain empty when join cluster without shards" in {
|
||||||
|
ClusterSharding(system).shardTypeNames should ===(Set())
|
||||||
|
}
|
||||||
|
|
||||||
|
"contain started shards when started 2 shards" in {
|
||||||
|
Cluster(system).join(Cluster(system).selfAddress)
|
||||||
|
val settings = ClusterShardingSettings(system)
|
||||||
|
ClusterSharding(system).start("type1", Props[EchoActor](), settings, extractEntityId, extractShardId)
|
||||||
|
ClusterSharding(system).start("type2", Props[EchoActor](), settings, extractEntityId, extractShardId)
|
||||||
|
|
||||||
|
ClusterSharding(system).shardTypeNames should ===(Set("type1", "type2"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue