Hi Harit,

The advice given by other are sound:

If you want to test "internal" actor behavior, then you can simply extract
it to a class, which you directly drive from the actor by calling methods
on it depending on the messages received. This way you can test it
separately and synchronously.

If you want to test interactions with external interfaces, then you should
provide them in the constructor or via an initializaton message. This way
you can substitute the real external service with the test implementation
you want.

We usually don't use Mocking frameworks, so I can't really comment on that
part.

-Endre

On Wed, May 27, 2015 at 8:38 AM, Harit Himanshu <
[email protected]> wrote:

> Frown upon mocks in actor testing, though they do have their place.
>
>
> This use case is perfect for mocks because the
>
> LogReaderDisruptor main(Array())
>
>
> is long running process (which will continue to run forever.
>
> To give you some context,  LogReaderDisruptor is entry to our current
> project as a single process.
>
> We are converting this to akka based project where first step is crash
> receovery, as in if Actor (running LogReaderDisruptor main(Array())) gets
> killed (because of some exception), we restart it.
>
> I can't comment on whether this is best design strategy, but this for sure
> adds value to our project and gives us ways to add fault tolerance to our
> application.
> Does that makes sense?
>
> Thanks
>
> On Tuesday, May 26, 2015 at 3:56:16 PM UTC-7, Harit Himanshu wrote:
>>
>> I am new to entire ecosystem including `Scala`, `Akka` and `ScalaTest`
>>
>> I am working on a problem where my `Actor` gives call to external system.
>>
>>     case object LogProcessRequest
>>
>>     class LProcessor extends Actor {
>>       val log = Logging(context.system, this)
>>
>>       def receive = {
>>         case LogProcessRequest =>
>>           log.debug("starting log processing")
>>           LogReaderDisruptor main(Array())
>>       }
>>     }
>>
>> The `LogReaderDisruptor main(Array())` is a `Java` class that does many
>> other things.
>>
>> The test I have currently looks like
>>
>>     class LProcessorSpec extends UnitTestSpec("testSystem") {
>>
>>       "A mocked log processor" should {
>>         "be called" in  {
>>           val logProcessorActor = system.actorOf(Props[LProcessor])
>>           logProcessorActor ! LogProcessRequest
>>         }
>>       }
>>     }
>>
>> where `UnitTestSpec` looks like (and inspired from [here][1])
>>
>>     import akka.actor.ActorSystem
>>     import akka.testkit.{ImplicitSender, TestKit}
>>     import org.scalatest.matchers.MustMatchers
>>     import org.scalatest.{BeforeAndAfterAll, WordSpecLike}
>>
>>     abstract class UnitTestSpec(name: String)
>>       extends TestKit(ActorSystem(name))
>>       with WordSpecLike
>>       with MustMatchers
>>       with BeforeAndAfterAll
>>       with ImplicitSender {
>>
>>       override def afterAll() {
>>         system.shutdown()
>>       }
>>     }
>>
>>
>> **Question**
>>
>> - How can I mock the call to `LogReaderDisruptor main(Array())` and
>> verify that it was called?
>>
>> I am coming from `Java`, `JUnit`, `Mockito` land and something that I
>> would have done here would be
>>
>>
>> doNothing().when(logReaderDisruptor).main(Matchers.<String>anyVararg())
>>     verify(logReaderDisruptor,
>> times(1)).main(Matchers.<String>anyVararg())
>>
>> I am not sure how to translate that with ScalaTest here.
>>
>> Also, This code may not be idiomatic, since I am very new and learning
>>
>>   [1]: http://www.superloopy.io/articles/2013/scalatest-with-akka.html
>>
>  --
> >>>>>>>>>> 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.
>



-- 
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

-- 
>>>>>>>>>>      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