Thanks Martynas, currently I am trying the TestActorRef approach which works.

On 16/05/15 10:12, Martynas Mickevičius wrote:
Hi Kostas,

I see two ways in approaching this. First, you could use TestActorRef to test the insides <http://doc.akka.io/docs/akka/2.3.11/scala/testing.html#Synchronous_Unit_Testing_with_TestActorRef> of your actor. In this way you could reach to the underlying instance of your actor and test each Receive block independently in a unit test fashion.

Now another approach is akin to integration testing when you test an actor by sending and expecting messages. In such case the actor either has to signal to the outside by a message that it has become a particular actor, or you have to periodically send messages and wait for a response for a finite period of time.

On Wed, May 13, 2015 at 9:09 AM, Kostas kougios <[email protected] <mailto:[email protected]>> wrote:

    Hi,

    Currently my actor becomes ready when it receives a msg :

    class MyActor {
        private val mediator =
    DistributedPubSubExtension(context.system).mediator
        mediator ! Subscribe(Subscriptions.Index, self)

    ...
        override def receive = {
            case SubscribeAck(Subscribe(Subscriptions.Index, None,
    self)) =>
                context become ready
        }

        def ready =
            createPart.receive orElse
                retrievePart.receive

    }

    This creates problems in test cases, when I send a msg to my actor:

    myActor ! Create(...) // this is received before SubscribeAck and
    hence it is ignored

    My temp solution is to sleep a bit after creating an actor so that
    I give an opportunity to the mediator to send the SubscribeAck:

            val indexActor =
    system.actorOf(Props(IndexActor.empty(IntKey, StringValue,
    cluster.ref)))
            // TODO: replace this with something better. This is
    required so that the actor becomes ready
            Thread.sleep(5)


    Is there a better solution?

    Thanks
    #
-- >>>>>>>>>> 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 [email protected]
    <mailto:[email protected]>.
    To post to this group, send email to [email protected]
    <mailto:[email protected]>.
    Visit this group at http://groups.google.com/group/akka-user.
    For more options, visit https://groups.google.com/d/optout.




--
Martynas Mickevičius
Typesafe <http://typesafe.com/> – Reactive <http://www.reactivemanifesto.org/> Apps on the JVM
--
>>>>>>>>>> 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/VpABoNODtNA/unsubscribe. To unsubscribe from this group and all its topics, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

--
     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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to