Akka Multi Node Testing

203 views
Skip to first unread message

jen

unread,
Sep 22, 2014, 12:28:01 AM9/22/14
to akka...@googlegroups.com

I tried  translate to Java of the existing Scala codes:

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 During the run with the arguments: -Dmultinode.max-nodes=4 -Dmultinode.host=127.0.0.1 etc. according to Multi Node Testing I will get the following error:

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)

is the internally generated ActorSystem name wrong?

Besides this I have two questions:
1. How can access the gossips from Java as in the Scala code,

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

as I have not found any way to implement the same in Java. My workaround is to subscribe to member events (see above), otherwise I do not know, is if this effectively the same or not?
2. Thunk function (the second argument of runOn method)? What is that? How can use it?

I appreciate your help.


Björn Antonsson

unread,
Sep 22, 2014, 12:50:32 PM9/22/14
to Akka User List
Hi,

Unfortunately the MultiNodeSpec has never really gotten a nice Java interface, but most functionality should be available.

Yes, the testkit code is unfortunately broken. An issue has been opened here https://github.com/akka/akka/issues/15956

Your code also has an problem. You shouldn't do "new Cluster(...)" but instead "Cluster.get(...)".



Besides this I have two questions:
1. How can access the gossips from Java as in the Scala code,

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

as I have not found any way to implement the same in Java. My workaround is to subscribe to member events (see above), otherwise I do not know, is if this effectively the same or not?


The awaitCond waits until you see the firstMember as Up, while your code will get a message for all member events. You could try to use the JavaTestKit instead by creating one inside the MultiNodeSpec.



2. Thunk function (the second argument of runOn method)? What is that? How can use it?


You should supply a function that runs the code that you want to run. It's a scala,Function, and you could implement it like this.


runOn(fisrtnodeseq, new AbstractFunction0<BoxedUnit>() {

    @Override

    public BoxedUnit apply() {

        // Do your thing here

        return null;

    }

});


B/



I appreciate your help.


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



-- 
Björn Antonsson
Typesafe – Reactive Apps on the JVM
twitter: @bantonsson

jen

unread,
Oct 5, 2014, 2:41:05 AM10/5/14
to akka...@googlegroups.com
Many thanks for the useful comments! Definitely I will learn Scala :) Could you tell me what is the expected due date of the 2.3.x milestone and how can I know which akka version has it corrected?

Martynas Mickevičius

unread,
Oct 7, 2014, 4:28:02 AM10/7/14
to akka...@googlegroups.com
Hi Jen,

when this bug is closed it will have a milestone corresponding to the Akka version it has been fixed.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Martynas Mickevičius

Csaba Jeney

unread,
Oct 7, 2014, 6:35:04 AM10/7/14
to akka...@googlegroups.com
Thank you!

Jen

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/huKR08sk_-k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
This message is intended to be confidential and may be privileged. If
you are not the intended recipient, please delete this e-mail from your
system immediately and notify us of the erroneous transmission to you.
Any unauthorized disclosure, use, copying, or distribution of this
E-mail is prohibited.

Please consider your environmental responsibility before printing this
e-mail.

________________________________

Ez az üzenet és bármely melléklete kizárólag a címzettnek szól. Tartalmazhat bizalmas, szellemi tulajdonnak minősülő illetve más jogvédett információkat vagy egyéb módon lehet védve jogszabályok által. Ha nem Ön a szándékozott címzettje, nem használhatja fel,nem hozhatja nyilvánosságra és nem másolhatja ezt az üzenetet, annak mellékletét vagy bármely részét, és nem cselekedhet az üzenet tartalmában bízva. Ebben az esetben kérjük, értesítse a feladót haladéktalanul, és törölje ezt az üzenetet és minden mellékletét rendszerébõl. A levél és tartalmának, felhatalmazás nélküli, másolása, arhíválása jogellenes.
A levél nyomtatásakor, kérjük, vegye figyelembe a környezetünk védelmét.

Slawek Mazur

unread,
Jun 29, 2016, 2:53:29 PM6/29/16
to Akka User List
Hi

did you manage to run this code sample? I'm on version 2.11:2.4.7 and I can't figure out how to configure MultiNode config for Java.


Best
SM

Csaba Jeney

unread,
Jul 5, 2016, 11:49:34 AM7/5/16
to akka...@googlegroups.com
Unfortunately not, I gave it up, as I had other duties.

Csaba
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/huKR08sk_-k/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
> To post to this group, send email to akka...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages