2012-05-15 09:40:13 +02:00
|
|
|
/**
|
2017-01-04 17:37:10 +01:00
|
|
|
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.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 }
|
2014-03-12 14:43:18 +01:00
|
|
|
import akka.routing.{ RoundRobinPool, FromConfig }
|
2016-11-01 11:12:53 +01:00
|
|
|
import akka.util.IgnoreForScala212
|
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 {
|
2014-08-29 14:40:49 +02:00
|
|
|
def receive = Actor.emptyBehavior
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyActorWithParam(ignore: String) extends Actor {
|
|
|
|
|
def receive = Actor.emptyBehavior
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DaemonMsgCreateSerializerSpec extends AkkaSpec {
|
|
|
|
|
|
|
|
|
|
import DaemonMsgCreateSerializerSpec._
|
|
|
|
|
val ser = SerializationExtension(system)
|
|
|
|
|
val supervisor = system.actorOf(Props[MyActor], "supervisor")
|
|
|
|
|
|
|
|
|
|
"Serialization" must {
|
|
|
|
|
|
|
|
|
|
"resolve DaemonMsgCreateSerializer" in {
|
2015-01-16 11:09:59 +01:00
|
|
|
ser.serializerFor(classOf[DaemonMsgCreate]).getClass should ===(classOf[DaemonMsgCreateSerializer])
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-08-29 14:40:49 +02:00
|
|
|
"serialize and de-serialize DaemonMsgCreate with FromClassCreator, with null parameters for Props" in {
|
|
|
|
|
verifySerialization {
|
|
|
|
|
DaemonMsgCreate(
|
|
|
|
|
props = Props(classOf[MyActorWithParam], null),
|
|
|
|
|
deploy = Deploy(),
|
|
|
|
|
path = "foo",
|
|
|
|
|
supervisor = supervisor)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 11:12:53 +01:00
|
|
|
"serialize and de-serialize DaemonMsgCreate with function creator" taggedAs IgnoreForScala212 in {
|
2012-05-15 18:22:40 +02:00
|
|
|
verifySerialization {
|
|
|
|
|
DaemonMsgCreate(
|
2014-01-17 09:12:44 +01:00
|
|
|
props = Props(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"),
|
2014-03-12 14:43:18 +01:00
|
|
|
routerConfig = RoundRobinPool(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
|
2015-01-16 11:09:59 +01:00
|
|
|
got.props.clazz should ===(expected.props.clazz)
|
|
|
|
|
got.props.args.length should ===(expected.props.args.length)
|
2013-04-14 22:56:41 +02:00
|
|
|
got.props.args zip expected.props.args foreach {
|
|
|
|
|
case (g, e) ⇒
|
|
|
|
|
if (e.isInstanceOf[Function0[_]]) ()
|
2015-01-16 11:09:59 +01:00
|
|
|
else g should ===(e)
|
2013-04-14 22:56:41 +02:00
|
|
|
}
|
2015-01-16 11:09:59 +01:00
|
|
|
got.props.deploy should ===(expected.props.deploy)
|
|
|
|
|
got.deploy should ===(expected.deploy)
|
|
|
|
|
got.path should ===(expected.path)
|
|
|
|
|
got.supervisor should ===(expected.supervisor)
|
2012-05-15 09:40:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|