--
>>>>>>>>>> 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/QM6Y69oYECM/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.
> ok,maybe POSO is not possible. But if I understand correctly, the only basic requirement for an actor is an Actor.Receive (a partial function).
Yes, and if you look in the akka.actor.Actor trait, that's the only abstract method required by that trait.
but it also contains the context, sender etc which as soon as MyActor extends Actor, they can't be easily mocked.
> The main "issue" is that actors extends Actor (which is nice and proper in terms of class hierarchy) with actor containing fields context, self, sender() etc. That's nice and convenient but it creates a few testability issues. i.e.
They mix in the trait, rather than extending a subclass.
Your example doesn't demonstrate any problem with subclasses v.s. POSOs.If I change the example code to be a POSO, there is still the exact same problem:
class MyParentPoso {
private val child = new ChildPoso()
...
child.say("hi") // how to test the communication between MyParentPoso and child?
}
Your example is one where Dependency Injection (rather than having the parent create its own collaborator) will lead to testable code:
class MyActor(collaborator: ActorRef) extends Actor {
...
collaborator ! "hi" // now you can test the communication
}
16 jun 2015 kl. 17:43 skrev 'Konstantinos Kougios' via Akka User List <akka...@googlegroups.com>:Hmm, context is not leaking, maybe from my example it is not obvious what is actually going on in the code.
Why mocking i.e. sender is code smell (for unit tests)?
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.
16 jun 2015 kl. 17:43 skrev 'Konstantinos Kougios' via Akka User List <akka...@googlegroups.com>:
Hmm, context is not leaking, maybe from my example it is not obvious what is actually going on in the code.
Why mocking i.e. sender is code smell (for unit tests)?
Why would you need special tricks to mock the sender of a message? You can just provide the sender’s ActorRef explicitly in the `.tell()` invocation.
While I appreciate that this is probably contentious my opinion is that mocking (in the magic sense, where stubs are created by waving the bytecode wand) is always a sign of a lack of proper tooling. And even with DI it tells you something about your code if writing tests for a single component requires a large amount of mocking and setup code—that component is quite likely too tightly coupled with too many other things.
17 jun 2015 kl. 16:18 skrev 'Konstantinos Kougios' via Akka User List <akka...@googlegroups.com>:hmm, maybe I need to, later on, put a small example into place to better see what usecase might be wrong or not.
I suppose creating a child actor within an actor is a typical use case and we need to be able to easy test it. Also self ! Msg too as it is i.e. required when actorSelector(...).resolveOne(... a future that self ! msg to avoid sync issues). My most complex use case is one of my server-actors receiving a msg from a driver-actor, all cluster server-actors must be informed about this message and upon confirmation the server-actor can complete this transaction.
some more answers below:On 17/06/15 14:50, Roland Kuhn wrote:sure , but the typical use case is to use the sender(). Avoiding that, solves this issue.16 jun 2015 kl. 17:43 skrev 'Konstantinos Kougios' via Akka User List <akka...@googlegroups.com>:Hmm, context is not leaking, maybe from my example it is not obvious what is actually going on in the code.
Why mocking i.e. sender is code smell (for unit tests)?Why would you need special tricks to mock the sender of a message? You can just provide the sender’s ActorRef explicitly in the `.tell()` invocation.
I agree (for the large scale mocking which shows problems in the design). But what is wrong say if we could magically mock the child actor and then:While I appreciate that this is probably contentious my opinion is that mocking (in the magic sense, where stubs are created by waving the bytecode wand) is always a sign of a lack of proper tooling. And even with DI it tells you something about your code if writing tests for a single component requires a large amount of mocking and setup code—that component is quite likely too tightly coupled with too many other things.
val childActor=mock[ActorRef] // ... and magically this is visible via our actor
actor ! Msg // this should make the actor do something and then to childActor ! AnOtherMsg
verify(childActor ! AnOtherMsg )