Akka群集分片-如何测试

时间:2020-04-24 14:50:55

标签: testing akka-cluster

我想测试一个使用ClusterSharing在某个时候询问EventSourcedBehaviorWithEnforcedReplies的函数

我像这样准备ClusterSharding:

  ClusterSharding.get(testKit.system()).init(
    Entity.of(
        ENTITY_TYPE_KEY,
        entityContext -> new Entity(entityContext.getEntityId())));

该函数发送命令:

CompletionStage<ActorAnswer> promisedAnswer = sharding
    .entityRefFor(ENTITY_TYPE_KEY, identifier)
    .ask(CommandToExecute::new, ASK_TIMEOUT)

CompletionStage永远不会执行...

我想念什么?

1 个答案:

答案 0 :(得分:0)

经过相同的研究

1)检查您的application-test.conf

akka {
  actor {
    provider = cluster
  }
}

2)需要创建集群并加入集群(自我加入),这是我发现的最简单的编程方式

Cluster cluster = Cluster.get(testKit.system());
cluster.manager().tell(Join.create(cluster.selfMember().address()));

3)然后我们可以讨论集群分片:)

  ClusterSharding.get(testKit.system()).init(
  clusterSharding.init(
    Entity.of(ENTITY_TYPE_KEY, entityContext -> new Entity(entityContext.getEntityId())));