2012-05-15 09:40:13 +02:00
|
|
|
/**
|
2013-01-09 01:47:48 +01:00
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
2012-05-15 09:40:13 +02:00
|
|
|
*/
|
|
|
|
|
|
2012-09-17 12:54:08 +02:00
|
|
|
package akka.remote.serialization
|
2012-05-15 09:40:13 +02:00
|
|
|
|
2012-06-25 16:29:08 +02:00
|
|
|
import language.postfixOps
|
|
|
|
|
|
2012-09-17 12:54:08 +02:00
|
|
|
import akka.serialization.SerializationExtension
|
2012-05-15 09:40:13 +02:00
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
import akka.testkit.AkkaSpec
|
2013-04-14 22:56:41 +02:00
|
|
|
import akka.actor.{ Actor, Address, Props, Deploy, OneForOneStrategy, SupervisorStrategy }
|
2012-06-25 16:29:08 +02:00
|
|
|
import akka.remote.{ DaemonMsgCreate, RemoteScope }
|
|
|
|
|
import akka.routing.{ RoundRobinRouter, FromConfig }
|
2012-09-21 14:50:06 +02:00
|
|
|
import scala.concurrent.duration._
|
2012-05-15 09:40:13 +02:00
|
|
|
|
|
|
|
|
object DaemonMsgCreateSerializerSpec {
|
|
|
|
|
class MyActor extends Actor {
|
|
|
|
|
def receive = {
|
|
|
|
|
case _ ⇒
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
|
|
|
|
class DaemonMsgCreateSerializerSpec extends AkkaSpec {
|
|
|
|
|
|
|
|
|
|
import DaemonMsgCreateSerializerSpec._
|
|
|
|
|
val ser = SerializationExtension(system)
|
|
|
|
|
val supervisor = system.actorOf(Props[MyActor], "supervisor")
|
|
|
|
|
|
|
|
|
|
"Serialization" must {
|
|
|
|
|
|
|
|
|
|
"resolve DaemonMsgCreateSerializer" in {
|
|
|
|
|
ser.serializerFor(classOf[DaemonMsgCreate]).getClass must be(classOf[DaemonMsgCreateSerializer])
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-15 18:22:40 +02:00
|
|
|
"serialize and de-serialize DaemonMsgCreate with FromClassCreator" in {
|
|
|
|
|
verifySerialization {
|
|
|
|
|
DaemonMsgCreate(
|
|
|
|
|
props = Props[MyActor],
|
|
|
|
|
deploy = Deploy(),
|
|
|
|
|
path = "foo",
|
|
|
|
|
supervisor = supervisor)
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
2012-05-15 18:22:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"serialize and de-serialize DaemonMsgCreate with function creator" in {
|
|
|
|
|
verifySerialization {
|
|
|
|
|
DaemonMsgCreate(
|
2012-08-20 21:42:50 +02:00
|
|
|
props = Props.empty.withCreator(new MyActor),
|
2012-05-15 18:22:40 +02:00
|
|
|
deploy = Deploy(),
|
|
|
|
|
path = "foo",
|
|
|
|
|
supervisor = supervisor)
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"serialize and de-serialize DaemonMsgCreate with Deploy and RouterConfig" in {
|
2012-05-15 18:22:40 +02:00
|
|
|
verifySerialization {
|
|
|
|
|
// Duration.Inf doesn't equal Duration.Inf, so we use another for test
|
|
|
|
|
val supervisorStrategy = OneForOneStrategy(3, 10 seconds) {
|
|
|
|
|
case _ ⇒ SupervisorStrategy.Escalate
|
|
|
|
|
}
|
|
|
|
|
val deploy1 = Deploy(
|
|
|
|
|
path = "path1",
|
|
|
|
|
config = ConfigFactory.parseString("a=1"),
|
|
|
|
|
routerConfig = RoundRobinRouter(nrOfInstances = 5, supervisorStrategy = supervisorStrategy),
|
2013-04-05 16:12:45 +02:00
|
|
|
scope = RemoteScope(Address("akka", "Test", "host1", 1921)),
|
|
|
|
|
dispatcher = "mydispatcher")
|
2012-05-15 18:22:40 +02:00
|
|
|
val deploy2 = Deploy(
|
|
|
|
|
path = "path2",
|
|
|
|
|
config = ConfigFactory.parseString("a=2"),
|
|
|
|
|
routerConfig = FromConfig,
|
2013-04-05 16:12:45 +02:00
|
|
|
scope = RemoteScope(Address("akka", "Test", "host2", 1922)),
|
|
|
|
|
dispatcher = Deploy.NoDispatcherGiven)
|
2012-05-15 18:22:40 +02:00
|
|
|
DaemonMsgCreate(
|
|
|
|
|
props = Props[MyActor].withDispatcher("my-disp").withDeploy(deploy1),
|
|
|
|
|
deploy = deploy2,
|
|
|
|
|
path = "foo",
|
|
|
|
|
supervisor = supervisor)
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
2012-05-15 18:22:40 +02:00
|
|
|
}
|
2012-05-15 09:40:13 +02:00
|
|
|
|
2012-05-15 18:22:40 +02:00
|
|
|
def verifySerialization(msg: DaemonMsgCreate): Unit = {
|
2012-09-06 03:17:51 +02:00
|
|
|
assertDaemonMsgCreate(msg, ser.deserialize(ser.serialize(msg).get, classOf[DaemonMsgCreate]).get.asInstanceOf[DaemonMsgCreate])
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def assertDaemonMsgCreate(expected: DaemonMsgCreate, got: DaemonMsgCreate): Unit = {
|
2012-05-15 18:22:40 +02:00
|
|
|
// can't compare props.creator when function
|
2013-04-14 22:56:41 +02:00
|
|
|
assert(got.props.clazz === expected.props.clazz)
|
|
|
|
|
assert(got.props.args.length === expected.props.args.length)
|
|
|
|
|
got.props.args zip expected.props.args foreach {
|
|
|
|
|
case (g, e) ⇒
|
|
|
|
|
if (e.isInstanceOf[Function0[_]]) ()
|
|
|
|
|
else assert(g === e)
|
|
|
|
|
}
|
2012-05-15 09:40:13 +02:00
|
|
|
assert(got.props.deploy === expected.props.deploy)
|
|
|
|
|
assert(got.deploy === expected.deploy)
|
|
|
|
|
assert(got.path === expected.path)
|
|
|
|
|
assert(got.supervisor === expected.supervisor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|