2009-07-01 15:29:06 +02:00
|
|
|
/**
|
2009-12-27 16:01:53 +01:00
|
|
|
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
2009-07-01 15:29:06 +02:00
|
|
|
*/
|
|
|
|
|
|
2009-09-03 11:02:21 +02:00
|
|
|
package se.scalablesolutions.akka.actor
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2010-05-01 12:59:24 +02:00
|
|
|
import java.util.concurrent.{LinkedBlockingQueue, TimeUnit, BlockingQueue}
|
2010-03-25 21:50:27 +01:00
|
|
|
import se.scalablesolutions.akka.serialization.BinaryString
|
2009-11-11 22:48:49 +01:00
|
|
|
import se.scalablesolutions.akka.config.ScalaConfig._
|
2009-12-16 23:20:15 +01:00
|
|
|
import se.scalablesolutions.akka.remote.{RemoteNode, RemoteServer}
|
2009-12-11 16:37:44 +01:00
|
|
|
import se.scalablesolutions.akka.OneWay
|
|
|
|
|
import se.scalablesolutions.akka.dispatch.Dispatchers
|
2010-05-01 12:59:24 +02:00
|
|
|
import Actor._
|
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 {
|
2010-05-18 16:00:24 +02:00
|
|
|
val messageLog: BlockingQueue[String] = new LinkedBlockingQueue[String]
|
|
|
|
|
val oneWayLog = new LinkedBlockingQueue[String]
|
|
|
|
|
|
|
|
|
|
def clearMessageLogs {
|
|
|
|
|
messageLog.clear
|
|
|
|
|
oneWayLog.clear
|
|
|
|
|
}
|
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 {
|
|
|
|
|
def receive = {
|
|
|
|
|
case BinaryString("Ping") =>
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.put("ping")
|
2010-05-16 10:59:06 +02:00
|
|
|
self.reply("pong")
|
2009-12-11 16:37:44 +01:00
|
|
|
|
|
|
|
|
case OneWay =>
|
2010-05-18 16:00:24 +02:00
|
|
|
Log.oneWayLog.put("oneway")
|
2009-12-11 16:37:44 +01:00
|
|
|
|
|
|
|
|
case BinaryString("Die") =>
|
|
|
|
|
throw new RuntimeException("DIE")
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-13 15:40:49 +02:00
|
|
|
override def postRestart(reason: Throwable) {
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.put(reason.getMessage)
|
2009-12-11 16:37:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@serializable class RemotePingPong2Actor extends Actor {
|
|
|
|
|
def receive = {
|
|
|
|
|
case BinaryString("Ping") =>
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.put("ping")
|
2010-05-16 10:59:06 +02:00
|
|
|
self.reply("pong")
|
2009-12-11 16:37:44 +01:00
|
|
|
case BinaryString("Die") =>
|
|
|
|
|
throw new RuntimeException("DIE")
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-13 15:40:49 +02:00
|
|
|
override def postRestart(reason: Throwable) {
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.put(reason.getMessage)
|
2009-12-11 16:37:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@serializable class RemotePingPong3Actor extends Actor {
|
|
|
|
|
def receive = {
|
|
|
|
|
case BinaryString("Ping") =>
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.put("ping")
|
2010-05-16 10:59:06 +02:00
|
|
|
self.reply("pong")
|
2009-12-11 16:37:44 +01:00
|
|
|
case BinaryString("Die") =>
|
|
|
|
|
throw new RuntimeException("DIE")
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-13 15:40:49 +02:00
|
|
|
override def postRestart(reason: Throwable) {
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.put(reason.getMessage)
|
2009-12-11 16:37:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
/**
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2010-04-05 13:55:59 +02:00
|
|
|
class RemoteSupervisorSpec extends JUnitSuite {
|
2009-11-23 15:19:53 +01:00
|
|
|
|
2010-03-25 01:28:55 +01:00
|
|
|
se.scalablesolutions.akka.config.Config.config
|
2010-03-23 00:29:18 +01:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
new Thread(new Runnable() {
|
2009-11-20 08:29:31 +01:00
|
|
|
def run = {
|
2010-04-06 12:45:09 +02:00
|
|
|
RemoteNode.start(RemoteServer.HOSTNAME, 9988)
|
2009-11-20 08:29:31 +01:00
|
|
|
}
|
2009-07-01 15:29:06 +02:00
|
|
|
}).start
|
|
|
|
|
Thread.sleep(1000)
|
|
|
|
|
|
2010-05-06 08:13:12 +02:00
|
|
|
var pingpong1: ActorRef = _
|
|
|
|
|
var pingpong2: ActorRef = _
|
|
|
|
|
var pingpong3: ActorRef = _
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2010-05-18 16:00:24 +02:00
|
|
|
import Log._
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldStartServer = {
|
2010-04-01 15:15:44 +02:00
|
|
|
Log.messageLog.clear
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
2009-07-27 21:21:28 +02:00
|
|
|
(pingpong1 !! BinaryString("Ping")).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-05-18 16:00:24 +02:00
|
|
|
@Test def shouldStartServerForNestedSupervisorHierarchy = {
|
|
|
|
|
clearMessageLogs
|
|
|
|
|
val sup = getNestedSupervisorsAllForOneConf
|
|
|
|
|
sup.start
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-01 15:29:06 +02:00
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillSingleActorOneForOne = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong1 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldCallKillCallSingleActorOneForOne = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong1 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillSingleActorAllForOne = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong1 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldCallKillCallSingleActorAllForOne = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getSingleActorAllForOneSupervisor
|
2010-05-16 11:58:20 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong1 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-16 13:24:31 +02:00
|
|
|
@Test def shouldKillMultipleActorsOneForOne1 = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong1 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 16:00:24 +02:00
|
|
|
/*
|
|
|
|
|
// Uncomment when the same test passes in SupervisorSpec - pending bug
|
2010-05-16 13:24:31 +02:00
|
|
|
@Test def shouldKillMultipleActorsOneForOne2 = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2010-05-16 13:24:31 +02:00
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2010-05-16 13:24:31 +02:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong3 !! (BinaryString("Die"), 5000)
|
2010-05-16 13:24:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-05-16 13:24:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-05-16 20:15:08 +02:00
|
|
|
*/
|
2010-05-18 16:00:24 +02:00
|
|
|
@Test def shouldKillCallMultipleActorsOneForOne = {
|
|
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getMultipleActorsOneForOneConf
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong2 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong3 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong2 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong2 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong3 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
@Test def shouldKillMultipleActorsAllForOne = {
|
2010-05-18 16:00:24 +02:00
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getMultipleActorsAllForOneConf
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong2 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 16:00:24 +02:00
|
|
|
@Test def shouldCallKillCallMultipleActorsAllForOne = {
|
|
|
|
|
clearMessageLogs
|
2009-07-01 15:29:06 +02:00
|
|
|
val sup = getMultipleActorsAllForOneConf
|
2010-05-18 16:00:24 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong2 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong3 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2009-10-26 11:30:03 +01:00
|
|
|
intercept[RuntimeException] {
|
2010-05-18 16:00:24 +02:00
|
|
|
pingpong2 !! (BinaryString("Die"), 5000)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2010-04-01 15:15:44 +02:00
|
|
|
}
|
|
|
|
|
expect("DIE") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong2 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
|
2009-07-01 15:29:06 +02:00
|
|
|
expect("pong") {
|
2010-05-18 16:00:24 +02:00
|
|
|
(pingpong3 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-01 15:15:44 +02:00
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
2010-04-01 15:15:44 +02:00
|
|
|
expect("ping") {
|
2010-05-18 16:00:24 +02:00
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
@Test def shouldOneWayKillSingleActorOneForOne = {
|
|
|
|
|
clearMessageLogs
|
|
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
|
|
|
|
|
|
|
|
|
pingpong1 ! BinaryString("Die")
|
|
|
|
|
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 16:00:24 +02:00
|
|
|
@Test def shouldOneWayCallKillCallSingleActorOneForOne = {
|
|
|
|
|
clearMessageLogs
|
|
|
|
|
val sup = getSingleActorOneForOneSupervisor
|
|
|
|
|
|
|
|
|
|
pingpong1 ! OneWay
|
|
|
|
|
|
|
|
|
|
expect("oneway") {
|
|
|
|
|
oneWayLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
pingpong1 ! BinaryString("Die")
|
|
|
|
|
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
pingpong1 ! OneWay
|
|
|
|
|
|
|
|
|
|
expect("oneway") {
|
|
|
|
|
oneWayLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test def shouldRestartKilledActorsForNestedSupervisorHierarchy = {
|
|
|
|
|
clearMessageLogs
|
|
|
|
|
val sup = getNestedSupervisorsAllForOneConf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong2 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong3 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("ping") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("ping") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("ping") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
pingpong2 !! (BinaryString("Die"), 5000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
messageLog.poll(5 , TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("DIE") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong1 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong2 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("pong") {
|
|
|
|
|
(pingpong3 !! (BinaryString("Ping"), 5000)).getOrElse("nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect("ping") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("ping") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
expect("ping") {
|
|
|
|
|
messageLog.poll(5, TimeUnit.SECONDS)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
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.
|
|
|
|
|
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong1 = actorOf[RemotePingPong1Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong1.start
|
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 = {
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong1 = actorOf[RemotePingPong1Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong1.start
|
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 = {
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong1 = actorOf[RemotePingPong1Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong1.start
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong2 = actorOf[RemotePingPong2Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong2.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong2.start
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong3 = actorOf[RemotePingPong3Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong3.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong3.start
|
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 = {
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong1 = actorOf[RemotePingPong1Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-16 20:15:08 +02:00
|
|
|
pingpong1 = actorOf[RemotePingPong1Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong1.start
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong2 = actorOf[RemotePingPong2Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong2.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong2.start
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong3 = actorOf[RemotePingPong3Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong3.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-13 15:40:49 +02:00
|
|
|
pingpong3.start
|
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))
|
2010-05-16 11:58:20 +02:00
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong2,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
::
|
|
|
|
|
Supervise(
|
|
|
|
|
pingpong3,
|
|
|
|
|
LifeCycle(Permanent))
|
|
|
|
|
:: Nil))
|
2009-11-20 08:29:31 +01:00
|
|
|
factory.newInstance
|
2009-07-01 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getNestedSupervisorsAllForOneConf: Supervisor = {
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong1 = actorOf[RemotePingPong1Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong1.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-16 20:15:08 +02:00
|
|
|
pingpong1.start
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong2 = actorOf[RemotePingPong2Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong2.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-16 20:15:08 +02:00
|
|
|
pingpong2.start
|
2010-05-08 19:01:12 +02:00
|
|
|
pingpong3 = actorOf[RemotePingPong3Actor]
|
2010-04-06 12:45:09 +02:00
|
|
|
pingpong3.makeRemote(RemoteServer.HOSTNAME, 9988)
|
2010-05-16 20:15:08 +02:00
|
|
|
pingpong3.start
|
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
|
|
|
}
|