Defining a receive for TestProbe won't do anything.
Instead take a look at Auto-Pilot for the behavior that you 
want: http://doc.akka.io/docs/akka/current/scala/testing.html#Auto-Pilot

On Thursday, August 4, 2016 at 3:59:50 PM UTC-7, Maatary Okouya wrote:
>
> I am trying to get a test probe to reply with an acknowledgement, whenever 
> it receive any message .
>
> I wrote the following code in my test but it does not work:
>
> val chgtWriter = new TestProbe(system)  {
>
>           def receive: Receive = {
>
>             case m => println("receive messagereplying with ACK"); sender() ! 
> ACK
>
>           }
>
>         }
>
> Is there a way to do that. The actor that is actually sending the message 
> to the test probe is definitely running on another thread than the 
> TestThread. Below you can see the full test as currently crafted.
>
> feature("The changeSetActor periodically fetch new change set following a 
> schedule") {
>
>
> scenario("A ChangeSetActor fetch new changeset from a Fetcher Actor that 
> return a full and an empty ChangeSet"){
>
>
>   Given("a ChangeSetActor with a schedule of fetching a message every 10 
> seconds, a ChangeFetcher and a ChangeWriter")
>
>     val chgtFetcher = TestProbe()
>
>     val chgtWriter = new TestProbe(system)  {
>
>       def receive: Receive = {
>
>         case m => println("receive message {} replying with ACK"); sender() ! 
> ACK
>
>       }
>
>     }
>     val fromTime = Instant.now().truncatedTo(ChronoUnit.SECONDS)
>     val chgtActor = system.actorOf(ChangeSetActor.props(chgtWriter.ref, 
> chgtFetcher.ref, fromTime))
>
>   When("all are started")
>
>
>   Then("The Change Fetcher should receive at least 3 messages from the 
> ChangeSetActor within 40 seconds")
>
>     var changesetSNum = 1
>
>     val received = chgtFetcher.receiveWhile( 40 seconds) {
>
>       case FetchNewChangeSet(m) => {
>
>         println(s"received: FetchNewChangeSet(${m}")
>
>         if (changesetSNum == 1) {
>             chgtFetcher.reply(NewChangeSet(changeSet1))
>             changesetSNum += 1
>           }
>           else
>             chgtFetcher.reply(NoAvailableChangeSet)
>         }
>
>       }
>
>     received.size should be (3)
> }
>
> }
>
> The changeSetActor is fully tested and works. The test hang with the 
> ChangeWriter. It never receive a message in the receive method.
>

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to