>
> 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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
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