Akka集群共享--如何测试?

问题描述 投票:0回答:1

我想测试一个函数,该函数在某些时候使用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从未被执行......

我缺少什么?

testing akka-cluster
1个回答
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())));
© www.soinside.com 2019 - 2024. All rights reserved.