Merge pull request #23965 from danischroeter/shardingNamesTest

Provide access to known shard types add test #23912
This commit is contained in:
Christopher Batey 2017-11-13 07:44:35 +00:00 committed by GitHub
commit ad7f68f994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"))
}
}
}