Java提供Akka多节点测试?

时间:2014-08-28 17:02:14

标签: integration-testing akka

我已阅读有关Multi Node Testing的Akka Java文档,但所有代码都在Scala中。有什么理由吗?谷歌搜索也没有成功。

编辑: 为了减少这个问题的风滚草,我做了尝试:)。现有Scala代码migth对Java的简单翻译如下所示:

public class ClusterTest {

    protected RoleName first;

    @Test
    public void SimpleClusterListenerClusterJoinTest() throws Exception {
        new MultiNodeSpec(new MultiNodeConfig() {{
            first = this.role("first");
            second = this.role("second");
            third = this.role("third");
            this.commonConfig(ConfigFactory.parseString(
                "akka.crdt.convergent.leveldb.destroy-on-shutdown = on\n" +
                    "akka.actor.provider = akka.cluster.ClusterActorRefProvider\n" +
                "akka.cluster.auto-join = off\n" +
                "akka.cluster.auto-down = on\n" +
                "akka.loggers = [\"akka.testkit.TestEventListener\"]\n" +
                "akka.loglevel = INFO\n" +
                "akka.remote.log-remote-lifecycle-events = off")); }}) {
                    {
                        Address firstAddress = node(first).address();
                        @SuppressWarnings("serial")
                        ArrayList<RoleName> firstnode = new ArrayList<RoleName>() {{
                        add(first);
                        }};
                        Seq<RoleName> fisrtnodeseq = (Seq<RoleName>)JavaConversions.asScalaBuffer(firstnode).toList();                      
                        runOn(fisrtnodeseq, null);

                Cluster cluster = new Cluster((ExtendedActorSystem) system());
                cluster.join(firstAddress);
                // verify that single node becomes member
                cluster.subscribe(testActor(), MemberEvent.class);
                expectMsg(MemberUp.class);
                    }

                    @Override
                    public int initialParticipants() {
                        return roles().size();
                    }};

    }

}

HOWEVER在使用参数运行期间: 根据{{​​3}} -Dmultinode.max-nodes=4 -Dmultinode.host=127.0.0.1等等(如果我在这里列出编辑严重抱怨的所有论据:[]我将收到以下错误:

java.lang.IllegalArgumentException: invalid ActorSystem name [ClusterTest_2], must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-')
at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:497)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:141)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:118)
at akka.remote.testkit.MultiNodeSpec.<init>(MultiNodeSpec.scala:252)
at com.akkamint.demo.ClusterTest$2.<init>(ClusterTest.java:51)

是内部生成的ActorSystem名称错误吗?

除此之外,我有两个问题:

  1. 如何从Scala代码中访问Java中的闲话,

    awaitCond(Cluster(system).latestGossip.members.exists(m ⇒ m.address == firstAddress && m.status == Up))
    

    我还没有找到任何方法在Java中实现相同的功能。我的解决方法是订阅成员事件(见上文),否则我不知道,这实际上是否相同?

  2. Thunk函数(runOn方法的第二个参数)?那是什么?怎么用呢?

0 个答案:

没有答案