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.