jeudi 27 avril 2017

Testing a method with Akka Actor parameters

I have a task, which I need to test. This task takes some actors as parameters, so I created a test with a TestActor as follows:

Few questions: 1. Is it a normal practice to create ActorSystem for test purposes? 2. The code doesn't end. I have tried to

val system = ActorSystem("TestRoutingSystem")
val actorRef = system.actorOf(Props(new TestActor), name = "testActor")


var poisonReceived = false
var workReceived = 0
class TestActor extends Actor with Logging {
  def receive = {
    case msg: WorkerMessage =>
      workReceived += 1
    case x: Boolean => {
      poisonReceived = true
    }
  }
}

val t = new java.util.Timer()
val task = new TestTask(...)
task.run()
t.schedule(task, 10, 10)
system.shutdown()



Thread.sleep(150)
println(poisonReceived )
println(workReceived)

Aucun commentaire:

Enregistrer un commentaire