[akka-user] Re: Using TestProbe to automate test by replying automatically just to ensure that the test goes
thx all clear now !!! On Sunday, August 7, 2016 at 3:10:18 PM UTC-4, Henry Mai wrote: > > > What is testActor ? There is no variable of that name? what does it > represent ? > > testActor in the example is just some arbitrary actor that is created in > the test code (not shown in the docs). > > It refers to the B actor in this sentence: > "This code can be used to forward messages, e.g. in a chain A --> Probe > --> B, as long as a certain protocol is obeyed." > > It is just for example purposes you don't actually need to use an > additional actor. > > In your case (given the code you pasted before) you probably just want to > do this: > >1. val probe = TestProbe() >2. probe.setAutoPilot(new TestActor.AutoPilot { >3. def run(sender: ActorRef, msg: Any): TestActor.AutoPilot = >4. msg match { >5. case x ⇒ sender() ! ACK; TestActor.KeepRunning >6. } >7. }) > > > 1 - what is the current one referring to here: the next message or the > auto-pilot ? To me, this sentence is just confusing, as much as the > example. I believe i would need more help to understand it. > "current one" is referring to the current auto-pilot. > -- >> 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.
[akka-user] Re: Using TestProbe to automate test by replying automatically just to ensure that the test goes
> What is testActor ? There is no variable of that name? what does it represent ? testActor in the example is just some arbitrary actor that is created in the test code (not shown in the docs). It refers to the B actor in this sentence: "This code can be used to forward messages, e.g. in a chain A --> Probe --> B, as long as a certain protocol is obeyed." It is just for example purposes you don't actually need to use an additional actor. In your case (given the code you pasted before) you probably just want to do this: 1. val probe = TestProbe() 2. probe.setAutoPilot(new TestActor.AutoPilot { 3. def run(sender: ActorRef, msg: Any): TestActor.AutoPilot = 4. msg match { 5. case x ⇒ sender() ! ACK; TestActor.KeepRunning 6. } 7. }) > 1 - what is the current one referring to here: the next message or the auto-pilot ? To me, this sentence is just confusing, as much as the example. I believe i would need more help to understand it. "current one" is referring to the current auto-pilot. -- >> 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.
[akka-user] Re: Using TestProbe to automate test by replying automatically just to ensure that the test goes
I do not understand the following sentence either: The run method must return the auto-pilot for the next message, which may be KeepRunning to retain the current one or NoAutoPilot to switch it off. 1 - what is the current one referring to here: the next message or the auto-pilot ? To me, this sentence is just confusing, as much as the example. I believe i would need more help to understand it. On Friday, August 5, 2016 at 2:58:59 AM UTC-4, Henry Mai wrote: > > 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.
[akka-user] Re: Using TestProbe to automate test by replying automatically just to ensure that the test goes
I have seen it, but i simply don't understand it at all. 1. val probe = TestProbe() 2. probe.setAutoPilot(new TestActor.AutoPilot { 3. def run(sender: ActorRef, msg: Any): TestActor.AutoPilot = 4. msg match { 5. case "stop" ⇒ TestActor.NoAutoPilot 6. case x ⇒ testActor.tell(x, sender); TestActor.KeepRunning 7. } 8. }) What is testActor ? There is no variable of that name? what does it represent ? On Friday, August 5, 2016 at 2:58:59 AM UTC-4, Henry Mai wrote: > > 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.
[akka-user] Re: Using TestProbe to automate test by replying automatically just to ensure that the test goes
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.