Use the right serializers when checking bw compability of DaemonMsgCreateSerializer #22224

This commit is contained in:
Johan Andrén 2017-03-01 17:09:05 +01:00 committed by GitHub
parent 1989ef481d
commit a6bb7f7960

View file

@ -4,16 +4,15 @@
package akka.remote.serialization
import language.postfixOps
import akka.actor.{Actor, ActorRef, ActorSystem, Address, Deploy, ExtendedActorSystem, OneForOneStrategy, Props, SupervisorStrategy}
import akka.remote.{DaemonMsgCreate, RemoteScope}
import akka.routing.{FromConfig, RoundRobinPool}
import akka.serialization.SerializationExtension
import akka.testkit.{AkkaSpec, TestKit}
import com.typesafe.config.ConfigFactory
import akka.testkit.AkkaSpec
import akka.actor.{ Actor, ActorRef, Address, Deploy, ExtendedActorSystem, OneForOneStrategy, Props, SupervisorStrategy }
import akka.remote.{ DaemonMsgCreate, RemoteScope }
import akka.routing.{ FromConfig, RoundRobinPool }
import akka.util.ByteString
import scala.concurrent.duration._
import scala.language.postfixOps
object DaemonMsgCreateSerializerSpec {
@ -81,33 +80,46 @@ class DaemonMsgCreateSerializerSpec extends AkkaSpec {
}
"deserialize the old wire format with just class and field for props parameters (if possible)" in {
val serializer = new DaemonMsgCreateSerializer(system.asInstanceOf[ExtendedActorSystem])
val system = ActorSystem("DaemonMsgCreateSerializer-old-wire-format", ConfigFactory.parseString(
"""
# in 2.4 this is off by default, but in 2.5+ its on so we wouldn't
# get the right set of serializers (and since the old wire protocol doesn't
# contain serializer ids that will go unnoticed with unpleasant consequences)
akka.actor.enable-additional-serialization-bindings = off
"""))
// the oldSnapshot was created with the version of DemonMsgCreateSerializer in Akka 2.4.17. See issue #22224.
// It was created with:
/*
try {
val serializer = new DaemonMsgCreateSerializer(system.asInstanceOf[ExtendedActorSystem])
// the oldSnapshot was created with the version of DemonMsgCreateSerializer in Akka 2.4.17. See issue #22224.
// It was created with:
/*
import org.apache.commons.codec.binary.Hex.encodeHex
val bytes = serializer.toBinary(
DaemonMsgCreate(Props(classOf[MyActorWithParam], "a string"), Deploy.local, "/user/test", system.actorFor("/user")))
println(String.valueOf(encodeHex(bytes)))
*/
val oldBytesHex =
"0a6a12020a001a48616b6b612e72656d6f74652e73657269616c697a6174696f" +
"6e2e4461656d6f6e4d736743726561746553657269616c697a6572537065632" +
"44d794163746f7257697468506172616d22086120737472696e672a106a6176" +
"612e6c616e672e537472696e67122f0a00222baced000573720016616b6b612" +
"e6163746f722e4c6f63616c53636f706524000000000000000102000078701a" +
"0a2f757365722f74657374222b0a29616b6b613a2f2f4461656d6f6e4d73674" +
"3726561746553657269616c697a6572537065632f75736572"
val oldBytesHex =
"0a7112020a001a48616b6b612e72656d6f74652e73657269616c697a617" +
"4696f6e2e4461656d6f6e4d736743726561746553657269616c697a6572" +
"53706563244d794163746f7257697468506172616d220faced000574000" +
"86120737472696e672a106a6176612e6c616e672e537472696e67122f0a" +
"00222baced000573720016616b6b612e6163746f722e4c6f63616c53636" +
"f706524000000000000000102000078701a0a2f757365722f7465737422" +
"2b0a29616b6b613a2f2f4461656d6f6e4d7367437265617465536572696" +
"16c697a6572537065632f75736572"
import org.apache.commons.codec.binary.Hex.decodeHex
val oldBytes = decodeHex(oldBytesHex.toCharArray)
val result = serializer.fromBinary(oldBytes, classOf[DaemonMsgCreate])
import org.apache.commons.codec.binary.Hex.decodeHex
val oldBytes = decodeHex(oldBytesHex.toCharArray)
val result = serializer.fromBinary(oldBytes, classOf[DaemonMsgCreate])
result match {
case dmc: DaemonMsgCreate
dmc.props.args should ===(Seq("a string": Any))
result match {
case dmc: DaemonMsgCreate
dmc.props.args should ===(Seq("a string": Any))
}
} finally {
TestKit.shutdownActorSystem(system)
}
}