2009-07-01 15:29:06 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009 Scalable Solutions.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-09-03 11:02:21 +02:00
|
|
|
package se.scalablesolutions.akka.actor
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-11 22:48:49 +01:00
|
|
|
import se.scalablesolutions.akka.serialization.BinaryString
|
|
|
|
|
import se.scalablesolutions.akka.config.ScalaConfig._
|
2009-12-11 16:37:44 +01:00
|
|
|
import se.scalablesolutions.akka.nio.{RemoteNode, RemoteServer}
|
|
|
|
|
import se.scalablesolutions.akka.OneWay
|
|
|
|
|
import se.scalablesolutions.akka.dispatch.Dispatchers
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
import org.scalatest.junit.JUnitSuite
|
|
|
|
|
import org.junit.Test
|
2009-07-01 15:29:06 +02:00
|
|
|
|
|
|
|
|
object Log {
|
|
|
|
|
var messageLog: String = ""
|
2009-11-20 08:29:31 +01:00
|
|
|
var oneWayLog: String = ""
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2009-11-20 08:29:31 +01:00
|
|
|
|
2009-12-11 16:37:44 +01:00
|
|
|
|
|
|
|
|
@serializable class RemotePingPong1Actor extends Actor {
|
|
|
|
|
dispatcher = Dispatchers.newThreadBasedDispatcher(this)
|
|
|
|
|
def receive = {
|
|
|
|
|
case BinaryString("Ping") =>
|
|
|
|
|
Log.messageLog += "ping"
|
|
|
|
|
reply("pong")
|
|
|
|
|
|
|
|
|
|
case OneWay =>
|
|
|
|
|
Log.oneWayLog += "oneway"
|
|
|
|
|
|
|
|
|
|
case BinaryString("Die") =>
|
|
|
|
|
throw new RuntimeException("DIE")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) {
|
|
|
|
|
Log.messageLog += reason.asInstanceOf[Exception].getMessage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@serializable class RemotePingPong2Actor extends Actor {
|
|
|
|
|
dispatcher = Dispatchers.newThreadBasedDispatcher(this)
|
|
|
|
|
def receive = {
|
|
|
|
|
case BinaryString("Ping") =>
|
|
|
|
|
Log.messageLog += "ping"
|
|
|
|
|
reply("pong")
|
|
|
|
|
case BinaryString("Die") =>
|
|
|
|
|
throw new RuntimeException("DIE")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) {
|
|
|
|
|
Log.messageLog += reason.asInstanceOf[Exception].getMessage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@serializable class RemotePingPong3Actor extends Actor {
|
|
|
|
|
dispatcher = Dispatchers.newThreadBasedDispatcher(this)
|
|
|
|
|
def receive = {
|
|
|
|
|
case BinaryString("Ping") =>
|
|
|
|
|
Log.messageLog += "ping"
|
|
|
|
|
reply("pong")
|
|
|
|
|
case BinaryString("Die") =>
|
|
|
|
|
throw new RuntimeException("DIE")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) {
|
|
|
|
|
Log.messageLog += reason.asInstanceOf[Exception].getMessage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
/**
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2009-11-20 08:29:31 +01:00
|
|
|
class RemoteSupervisorTest extends JUnitSuite {
|
2009-11-23 15:19:53 +01:00
|
|
|
import Actor.Sender.Self
|
|
|
|
|
|
2009-09-03 11:02:21 +02:00
|
|
|
akka.Config.config
|
2009-07-01 15:29:06 +02:00
|
|
|
new Thread(new Runnable() {
|
2009-11-20 08:29:31 +01:00
|
|
|
def run = {
|
2009-11-25 12:42:50 +01:00
|
|
|
RemoteNode.start
|
2009-11-20 08:29:31 +01:00
|
|
|
}
|
2009-07-01 15:29:06 +02:00
|
|
|
}).start
|
|
|
|
|
Thread.sleep(1000)
|
|
|
|
|
|
|
|
|
|
var pingpong1: RemotePingPong1Actor = _
|
|
|
|
|
var pingpong2: RemotePingPong2Actor = _
|
|
|
|
|
var pingpong3: RemotePingPong3Actor = _
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldStartServer = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillSingleActorOneForOne = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldCallKillCallSingleActorOneForOne = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("ping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingDIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingDIEping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillSingleActorAllForOne = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldCallKillCallSingleActorAllForOne = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("ping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingDIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingDIEping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillMultipleActorsOneForOne = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong3 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def tesCallKillCallMultipleActorsOneForOne = {
|
|
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong2 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong3 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong2 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong2 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong3 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIEpingpingping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillMultipleActorsAllForOne = {
|
2009-07-01 15:29:06 +02:00
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsAllForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong2 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIEDIEDIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def tesCallKillCallMultipleActorsAllForOne = {
|
|
|
|
|
Log.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsAllForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong2 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong3 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong2 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIEDIEDIE") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong2 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong3 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIEDIEDIEpingpingping") {
|
|
|
|
|
Log.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-03 17:15:36 +02:00
|
|
|
/*
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldOneWayKillSingleActorOneForOne = {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.messageLog = ""
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 ! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.messageLog
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldOneWayCallKillCallSingleActorOneForOne = {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.messageLog = ""
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
pingpong1 ! OneWay
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("oneway") {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.oneWayLog
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 ! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.messageLog
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
pingpong1 ! OneWay
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("onewayoneway") {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.oneWayLog
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
2009-07-03 17:15:36 +02:00
|
|
|
*/
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-20 08:29:31 +01:00
|
|
|
/*
|
|
|
|
|
@Test def shouldOneWayKillSingleActorAllForOne = {
|
|
|
|
|
Logg.messageLog = ""
|
|
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-11-20 08:29:31 +01:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong1 ! BinaryString("Die")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test def shouldOneWayCallKillCallSingleActorAllForOne = {
|
|
|
|
|
Logg.messageLog = ""
|
|
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-11-20 08:29:31 +01:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("ping") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong1 ! BinaryString("Die")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingDIE") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingDIEping") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test def shouldOneWayKillMultipleActorsOneForOne = {
|
|
|
|
|
Logg.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-11-20 08:29:31 +01:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong3 ! BinaryString("Die")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def tesOneWayCallKillCallMultipleActorsOneForOne = {
|
|
|
|
|
Logg.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-11-20 08:29:31 +01:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong2 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong3 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingping") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong2 ! BinaryString("Die")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIE") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong2 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong3 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIEpingpingping") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test def shouldOneWayKillMultipleActorsAllForOne = {
|
|
|
|
|
Logg.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsAllForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-11-20 08:29:31 +01:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong2 ! BinaryString("Die")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIEDIEDIE") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def tesOneWayCallKillCallMultipleActorsAllForOne = {
|
|
|
|
|
Logg.messageLog = ""
|
|
|
|
|
val sup = getMultipleActorsAllForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-11-20 08:29:31 +01:00
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
pingpong1 ! BinaryString("Ping")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong2 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong3 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingping") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong2 ! BinaryString("Die")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIEDIEDIE") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong2 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong3 ! BinaryString("Ping")).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("pingpingpingDIEDIEDIEpingpingping") {
|
|
|
|
|
Logg.messageLog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
2009-07-01 15:29:06 +02:00
|
|
|
|
|
|
|
|
/*
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldNestedSupervisorsTerminateFirstLevelActorAllForOne = {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.messageLog = ""
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getNestedSupervisorsAllForOneConf
|
2009-11-21 19:34:42 +01:00
|
|
|
sup.start
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2009-07-27 21:21:28 +02:00
|
|
|
pingpong1 !! BinaryString("Die")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
Thread.sleep(500)
|
|
|
|
|
expect("DIEDIEDIE") {
|
2009-09-03 11:02:21 +02:00
|
|
|
Logg.messageLog
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
// Creat some supervisors with different configurations
|
|
|
|
|
|
|
|
|
|
def getSingleActorAllForOneSupervisor: Supervisor = {
|
|
|
|
|
|
|
|
|
|
// Create an abstract SupervisorContainer that works for all implementations
|
|
|
|
|
// of the different Actors (Services).
|
|
|
|
|
//
|
|
|
|
|
// Then create a concrete container in which we mix in support for the specific
|
|
|
|
|
// implementation of the Actors we want to use.
|
|
|
|
|
|
|
|
|
|
pingpong1 = new RemotePingPong1Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-20 08:29:31 +01:00
|
|
|
val factory = SupervisorFactory(
|
|
|
|
|
SupervisorConfig(
|
2009-11-30 21:22:24 +01:00
|
|
|
RestartStrategy(AllForOne, 3, 100, List(classOf[Exception])),
|
2009-11-20 08:29:31 +01:00
|
|
|
Supervise(
|
|
|
|
|
pingpong1,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
:: Nil))
|
|
|
|
|
|
|
|
|
|
factory.newInstance
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getSingleActorOneForOneSupervisor: Supervisor = {
|
|
|
|
|
pingpong1 = new RemotePingPong1Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-20 08:29:31 +01:00
|
|
|
val factory = SupervisorFactory(
|
|
|
|
|
SupervisorConfig(
|
2009-11-30 21:22:24 +01:00
|
|
|
RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
|
2009-11-20 08:29:31 +01:00
|
|
|
Supervise(
|
|
|
|
|
pingpong1,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
:: Nil))
|
|
|
|
|
factory.newInstance
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getMultipleActorsAllForOneConf: Supervisor = {
|
|
|
|
|
pingpong1 = new RemotePingPong1Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
pingpong2 = new RemotePingPong2Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong2.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
pingpong3 = new RemotePingPong3Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong3.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-20 08:29:31 +01:00
|
|
|
val factory = SupervisorFactory(
|
|
|
|
|
SupervisorConfig(
|
2009-11-30 21:22:24 +01:00
|
|
|
RestartStrategy(AllForOne, 3, 100, List(classOf[Exception])),
|
2009-11-20 08:29:31 +01:00
|
|
|
Supervise(
|
|
|
|
|
pingpong1,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong2,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong3,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
:: Nil))
|
|
|
|
|
factory.newInstance
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getMultipleActorsOneForOneConf: Supervisor = {
|
|
|
|
|
pingpong1 = new RemotePingPong1Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
pingpong2 = new RemotePingPong2Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong2.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
pingpong3 = new RemotePingPong3Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong3.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-20 08:29:31 +01:00
|
|
|
val factory = SupervisorFactory(
|
|
|
|
|
SupervisorConfig(
|
2009-11-30 21:22:24 +01:00
|
|
|
RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
|
2009-11-20 08:29:31 +01:00
|
|
|
Supervise(
|
|
|
|
|
pingpong1,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong2,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong3,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
:: Nil))
|
|
|
|
|
factory.newInstance
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getNestedSupervisorsAllForOneConf: Supervisor = {
|
|
|
|
|
pingpong1 = new RemotePingPong1Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
pingpong2 = new RemotePingPong2Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong2.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
pingpong3 = new RemotePingPong3Actor
|
2009-07-02 13:23:03 +02:00
|
|
|
pingpong3.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-11-20 08:29:31 +01:00
|
|
|
val factory = SupervisorFactory(
|
|
|
|
|
SupervisorConfig(
|
2009-11-30 21:22:24 +01:00
|
|
|
RestartStrategy(AllForOne, 3, 100, List(classOf[Exception])),
|
2009-11-20 08:29:31 +01:00
|
|
|
Supervise(
|
|
|
|
|
pingpong1,
|
|
|
|
|
LifeCycle(Permanent))
|
2009-07-01 15:29:06 +02:00
|
|
|
::
|
2009-11-20 08:29:31 +01:00
|
|
|
SupervisorConfig(
|
2009-11-30 21:22:24 +01:00
|
|
|
RestartStrategy(AllForOne, 3, 100, List(classOf[Exception])),
|
2009-11-20 08:29:31 +01:00
|
|
|
Supervise(
|
|
|
|
|
pingpong2,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong3,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
:: Nil)
|
|
|
|
|
:: Nil))
|
|
|
|
|
factory.newInstance
|
|
|
|
|
}
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|