I'd even say: "I'd like to write a test that checks that if this function is called that system.scheduler.scheduleOnce is called with the correct delay."
This is testing Akka, and is already tested within Akka. :) On Thu, Sep 10, 2015 at 11:33 AM, Akka Team <[email protected]> wrote: > Hi Elisabeth, > > system.scheduler implements the interface Scheduler. You can stub that > interface without mocking an ActorSystem. That will be enough to test that > a proper scheduled job was created. > > -Endre > > On Wed, Sep 9, 2015 at 6:03 PM, Elisabeth Anderson <[email protected]> wrote: > >> I'm not sure if I'm approaching this in the correct way, but... >> >> I have a client which, when called, will create a schedule, such as: >> >> def schedule(item: Map[String, String], delay: FiniteDuration): >> Cancellable = { >> val job = ScheduledJob(item, delay) >> >> system.scheduler.scheduleOnce(delay) { >> jobRunnerActor ! job >> } >> } >> >> I'd like to write a test that checks that if this function is called that >> system.scheduler.scheduleOnce is called with the correct delay. >> >> I've written the following test: >> >> "Orchestration" should { >> "schedule a job once using the actor system" in new Actors { >> >> val item = Map( >> "type" -> "foo", >> "id" -> "bar" >> ) >> >> val delay = FiniteDuration(1, "second") >> >> // DI the mock ActorSystem >> object MockOrchestrator extends Orchestration { >> val system = mock[ActorSystem] >> } >> >> // stubs >> val result: Cancellable = mock[Cancellable] >> MockOrchestrator.schedule(any[Map[String, String]], >> any[FiniteDuration]) returns result >> >> // run the scheduler >> MockOrchestrator.schedule(item, delay) >> >> val jobRunnerActor = system.actorOf(Props[JobRunnerActor]) >> >> val job = { >> jobRunnerActor ! ScheduledJob(item, delay) >> } >> >> // system.scheduler.scheduleOnce should be run with the correct delay >> there was one(mockSystem.scheduler).scheduleOnce(delay)(job) >> } >> } >> >> With this test I'm setting up a MockOrchestrator as the 'system' is being >> passed to this using dependency injection (so I can pass in a mock actor >> system). Then I'm setting up a stub of the schedule function, running it, >> then ensuring that the scheduler was called with the delay and the function >> to run. >> >> However, this isn't running. I think because of the (job) function I'm >> passing to the check for 'there was one' >> >> Like I say, I'm not sure if this is the correct approach. I don't want to >> test the Akka scheduler, just that my code creates a proper scheduled job. >> How should I approach this? >> >> Thanks, >> >> Beth >> >> -- >> >>>>>>>>>> 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. > -- Cheers, √ -- >>>>>>>>>> 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.
