2018-03-27 11:20:20 +01:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2018-2020 Lightbend Inc. <https://www.lightbend.com>
|
2018-03-27 11:20:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.remote
|
|
|
|
|
|
|
|
|
|
import akka.actor.{ Actor, ActorIdentity, ActorSystem, ExtendedActorSystem, Identify, Props, RootActorPath }
|
|
|
|
|
import akka.testkit.{ AkkaSpec, ImplicitSender, TestKit }
|
|
|
|
|
import com.typesafe.config.{ Config, ConfigFactory }
|
|
|
|
|
import MessageLoggingSpec._
|
Disable Java serialization by default, #22333 (#27285)
* akka.actor.allow-java-serialization = off
* Moved primitive (Long, Int, String, ByteString) serializers
from akka-remote to akka-actor since they had no dependency
and are useful also in local systems, e.g. persistence.
* e.g. needed for persistence-tck
* less allow-java-serialization=on in tests
* CborSerializable in Jackson/test module for ease of use
* JavaSerializable for Java serialization in tests, already in akka-testkit,
but misconfigured
* Made tests pass
* allow-java-serialization=on in akka-persistence
* allow-java-serialization=on in classic remoting tests
* JavaSerializable and CborSerializable in other remoting tests
* Added serialization for
* Boolean
* java.util.concurrent.TimeoutException, AskTimeoutException
* support for testing serialization with the inmem journal
* utility to verifySerialization, in SerializationTestKit
* remove AccountExampleWithCommandHandlersInState becuase not possible to serialize State when it's not static
* Effect() is factory in EventSourcedBehavior class
* test the account examples
* SharedLeveldbJournal.configToEnableJavaSerializationForTest
* support for exceptions from remote deployed child actors
* fallback to akka.remote.serialization.ThrowableNotSerializableException
if exception is not serializable when wrapped in system messages from
remote deployed child actors and Status.Failure messages
* it's implemented in `WrappedPayloadSupport.payloadBuilder`
* update reference documentation
* serialize-messages=off in most places, separate ticket for
improving or removing that feature
* migration guide, including description of rolling update
* fix 2.13 compiler error
* minor review feedback
2019-07-11 14:04:24 +02:00
|
|
|
import akka.serialization.jackson.CborSerializable
|
2018-03-27 11:20:20 +01:00
|
|
|
|
|
|
|
|
object MessageLoggingSpec {
|
2019-03-11 10:38:24 +01:00
|
|
|
def config(artery: Boolean) = ConfigFactory.parseString(s"""
|
2018-03-27 11:20:20 +01:00
|
|
|
akka.loglevel = info // debug makes this test fail intentionally
|
|
|
|
|
akka.actor.provider = remote
|
|
|
|
|
akka.remote {
|
2019-05-01 08:12:09 +01:00
|
|
|
|
|
|
|
|
classic {
|
2018-03-27 11:20:20 +01:00
|
|
|
log-received-messages = on
|
|
|
|
|
log-sent-messages = on
|
|
|
|
|
netty.tcp {
|
|
|
|
|
hostname = localhost
|
|
|
|
|
port = 0
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-01 08:12:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artery {
|
|
|
|
|
enabled = $artery
|
|
|
|
|
transport = aeron-udp
|
|
|
|
|
canonical.hostname = localhost
|
|
|
|
|
canonical.port = 0
|
|
|
|
|
log-received-messages = on
|
|
|
|
|
log-sent-messages = on
|
|
|
|
|
}
|
2018-03-27 11:20:20 +01:00
|
|
|
}
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
|
Disable Java serialization by default, #22333 (#27285)
* akka.actor.allow-java-serialization = off
* Moved primitive (Long, Int, String, ByteString) serializers
from akka-remote to akka-actor since they had no dependency
and are useful also in local systems, e.g. persistence.
* e.g. needed for persistence-tck
* less allow-java-serialization=on in tests
* CborSerializable in Jackson/test module for ease of use
* JavaSerializable for Java serialization in tests, already in akka-testkit,
but misconfigured
* Made tests pass
* allow-java-serialization=on in akka-persistence
* allow-java-serialization=on in classic remoting tests
* JavaSerializable and CborSerializable in other remoting tests
* Added serialization for
* Boolean
* java.util.concurrent.TimeoutException, AskTimeoutException
* support for testing serialization with the inmem journal
* utility to verifySerialization, in SerializationTestKit
* remove AccountExampleWithCommandHandlersInState becuase not possible to serialize State when it's not static
* Effect() is factory in EventSourcedBehavior class
* test the account examples
* SharedLeveldbJournal.configToEnableJavaSerializationForTest
* support for exceptions from remote deployed child actors
* fallback to akka.remote.serialization.ThrowableNotSerializableException
if exception is not serializable when wrapped in system messages from
remote deployed child actors and Status.Failure messages
* it's implemented in `WrappedPayloadSupport.payloadBuilder`
* update reference documentation
* serialize-messages=off in most places, separate ticket for
improving or removing that feature
* migration guide, including description of rolling update
* fix 2.13 compiler error
* minor review feedback
2019-07-11 14:04:24 +02:00
|
|
|
case class BadMsg(msg: String) extends CborSerializable {
|
2018-03-27 11:20:20 +01:00
|
|
|
override def toString = throw new RuntimeException("Don't log me")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BadActor extends Actor {
|
|
|
|
|
override def receive = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case _ =>
|
2018-03-27 11:20:20 +01:00
|
|
|
sender() ! BadMsg("hah")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ArteryMessageLoggingSpec extends MessageLoggingSpec(config(true))
|
|
|
|
|
class ClassicMessageLoggingSpec extends MessageLoggingSpec(config(false))
|
|
|
|
|
|
|
|
|
|
abstract class MessageLoggingSpec(config: Config) extends AkkaSpec(config) with ImplicitSender {
|
|
|
|
|
|
2018-04-03 08:03:57 +01:00
|
|
|
val remoteSystem = ActorSystem("remote-sys", ConfigFactory.load(config))
|
2018-03-27 11:20:20 +01:00
|
|
|
val remoteAddress = remoteSystem.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
2018-04-03 08:03:57 +01:00
|
|
|
|
2018-03-27 11:20:20 +01:00
|
|
|
"Message logging" must {
|
|
|
|
|
"not be on if debug logging not enabled" in {
|
|
|
|
|
remoteSystem.actorOf(Props[BadActor], "bad")
|
|
|
|
|
val as = system.actorSelection(RootActorPath(remoteAddress) / "user" / "bad")
|
|
|
|
|
as ! Identify("bad")
|
|
|
|
|
val ref = expectMsgType[ActorIdentity].ref.get
|
|
|
|
|
ref ! "hello"
|
|
|
|
|
expectMsgType[BadMsg]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected def afterTermination(): Unit = {
|
|
|
|
|
TestKit.shutdownActorSystem(remoteSystem)
|
|
|
|
|
}
|
|
|
|
|
}
|