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
This commit is contained in:
Patrik Nordwall 2019-07-11 14:04:24 +02:00 committed by GitHub
parent a4f090b622
commit 3efc1c2877
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
191 changed files with 4041 additions and 2321 deletions

View file

@ -85,7 +85,9 @@ abstract class ClusterShardingCustomShardAllocationSpecConfig(val mode: String)
val first = role("first")
val second = role("second")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.actor.provider = "cluster"
akka.remote.log-remote-lifecycle-events = off
akka.persistence.journal.plugin = "akka.persistence.journal.leveldb-shared"
@ -101,7 +103,9 @@ abstract class ClusterShardingCustomShardAllocationSpecConfig(val mode: String)
akka.cluster.sharding.state-store-mode = "$mode"
akka.cluster.sharding.rebalance-interval = 1 s
#akka.cluster.sharding.retry-interval = 5 s
""").withFallback(MultiNodeClusterSpec.clusterConfig))
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
}
object PersistentClusterShardingCustomShardAllocationSpecConfig

View file

@ -7,8 +7,8 @@ package akka.cluster.sharding
import java.io.File
import akka.cluster.sharding.ShardRegion.Passivate
import scala.concurrent.duration._
import org.apache.commons.io.FileUtils
import com.typesafe.config.ConfigFactory
import akka.actor._
@ -21,14 +21,15 @@ import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.remote.testkit.STMultiNodeSpec
import akka.remote.transport.ThrottlerTransportAdapter.Direction
import akka.serialization.jackson.CborSerializable
import akka.testkit._
import akka.util.ccompat._
@ccompatUsedUntil213
object ClusterShardingFailureSpec {
case class Get(id: String)
case class Add(id: String, i: Int)
case class Value(id: String, n: Int)
case class Get(id: String) extends CborSerializable
case class Add(id: String, i: Int) extends CborSerializable
case class Value(id: String, n: Int) extends CborSerializable
class Entity extends Actor {
var n = 0
@ -56,7 +57,9 @@ abstract class ClusterShardingFailureSpecConfig(val mode: String) extends MultiN
val first = role("first")
val second = role("second")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.remote.classic.log-remote-lifecycle-events = off
@ -81,7 +84,14 @@ abstract class ClusterShardingFailureSpecConfig(val mode: String) extends MultiN
dir = target/ClusterShardingFailureSpec/sharding-ddata
map-size = 10 MiB
}
""").withFallback(MultiNodeClusterSpec.clusterConfig))
# using Java serialization for these messages because test is sending them
# to other nodes, which isn't normal usage.
akka.actor.serialization-bindings {
"${classOf[ShardRegion.Passivate].getName}" = java-test
}
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
testTransport(on = true)
}

View file

@ -11,13 +11,14 @@ import akka.remote.testconductor.RoleName
import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec, STMultiNodeSpec }
import akka.testkit.TestProbe
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
import akka.serialization.jackson.CborSerializable
object ClusterShardingGetStateSpec {
case object Stop
case class Ping(id: Long)
case object Pong
case object Stop extends CborSerializable
case class Ping(id: Long) extends CborSerializable
case object Pong extends CborSerializable
class ShardedActor extends Actor with ActorLogging {
log.info(self.path.toString)
@ -45,7 +46,7 @@ object ClusterShardingGetStateSpecConfig extends MultiNodeConfig {
val first = role("first")
val second = role("second")
commonConfig(ConfigFactory.parseString("""
commonConfig(ConfigFactory.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.remote.log-remote-lifecycle-events = off
@ -59,6 +60,12 @@ object ClusterShardingGetStateSpecConfig extends MultiNodeConfig {
dir = target/ClusterShardingGetStateSpec/sharding-ddata
map-size = 10 MiB
}
# using Java serialization for these messages because test is sending them
# to other nodes, which isn't normal usage.
akka.actor.serialization-bindings {
"${ShardRegion.GetShardRegionState.getClass.getName}" = java-test
"${classOf[ShardRegion.CurrentShardRegionState].getName}" = java-test
}
""").withFallback(MultiNodeClusterSpec.clusterConfig))
nodeConfig(first, second)(ConfigFactory.parseString("""akka.cluster.roles=["shard"]"""))

View file

@ -10,13 +10,14 @@ import akka.remote.testconductor.RoleName
import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec, STMultiNodeSpec }
import akka.testkit.{ TestDuration, TestProbe }
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
import akka.serialization.jackson.CborSerializable
object ClusterShardingGetStatsSpec {
case object Stop
case class Ping(id: Long)
case object Pong
case object Stop extends CborSerializable
case class Ping(id: Long) extends CborSerializable
case object Pong extends CborSerializable
class ShardedActor extends Actor with ActorLogging {
log.info(s"entity started {}", self.path)
@ -60,7 +61,6 @@ object ClusterShardingGetStatsSpecConfig extends MultiNodeConfig {
dir = target/ClusterShardingGetStatsSpec/sharding-ddata
map-size = 10 MiB
}
akka.actor.warn-about-java-serializer-usage=false
""").withFallback(MultiNodeClusterSpec.clusterConfig))
nodeConfig(first, second, third)(ConfigFactory.parseString("""akka.cluster.roles=["shard"]"""))

View file

@ -46,7 +46,9 @@ abstract class ClusterShardingGracefulShutdownSpecConfig(val mode: String) exten
val first = role("first")
val second = role("second")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.remote.log-remote-lifecycle-events = off
@ -65,7 +67,9 @@ abstract class ClusterShardingGracefulShutdownSpecConfig(val mode: String) exten
dir = target/ClusterShardingGracefulShutdownSpec/sharding-ddata
map-size = 10 MiB
}
""").withFallback(MultiNodeClusterSpec.clusterConfig))
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
}
object PersistentClusterShardingGracefulShutdownSpecConfig

View file

@ -7,6 +7,7 @@ package akka.cluster.sharding
import java.io.File
import scala.concurrent.duration._
import akka.actor.Actor
import akka.actor.ActorIdentity
import akka.actor.ActorRef
@ -20,12 +21,13 @@ import akka.remote.testconductor.RoleName
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.remote.testkit.STMultiNodeSpec
import akka.serialization.jackson.CborSerializable
import akka.testkit._
import com.typesafe.config.ConfigFactory
import org.apache.commons.io.FileUtils
object ClusterShardingLeavingSpec {
case class Ping(id: String)
case class Ping(id: String) extends CborSerializable
class Entity extends Actor {
def receive = {
@ -33,8 +35,8 @@ object ClusterShardingLeavingSpec {
}
}
case object GetLocations
case class Locations(locations: Map[String, ActorRef])
case object GetLocations extends CborSerializable
case class Locations(locations: Map[String, ActorRef]) extends CborSerializable
class ShardLocations extends Actor {
var locations: Locations = _
@ -59,7 +61,9 @@ abstract class ClusterShardingLeavingSpecConfig(val mode: String) extends MultiN
val third = role("third")
val fourth = role("fourth")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.remote.classic.log-remote-lifecycle-events = off
@ -79,7 +83,9 @@ abstract class ClusterShardingLeavingSpecConfig(val mode: String) extends MultiN
dir = target/ClusterShardingLeavingSpec/sharding-ddata
map-size = 10 MiB
}
""").withFallback(MultiNodeClusterSpec.clusterConfig))
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
}
object PersistentClusterShardingLeavingSpecConfig extends ClusterShardingLeavingSpecConfig("persistence")

View file

@ -41,7 +41,9 @@ abstract class ClusterShardingMinMembersSpecConfig(val mode: String) extends Mul
val second = role("second")
val third = role("third")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.remote.log-remote-lifecycle-events = off
@ -62,7 +64,9 @@ abstract class ClusterShardingMinMembersSpecConfig(val mode: String) extends Mul
map-size = 10 MiB
}
akka.cluster.min-nr-of-members = 3
""").withFallback(MultiNodeClusterSpec.clusterConfig))
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
}
object PersistentClusterShardingMinMembersSpecConfig extends ClusterShardingMinMembersSpecConfig("persistence")

View file

@ -57,7 +57,9 @@ abstract class ClusterShardingRememberEntitiesNewExtractorSpecConfig(val mode: S
val second = role("second")
val third = role("third")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.actor.provider = "cluster"
akka.cluster.auto-down-unreachable-after = 0s
akka.remote.classic.log-remote-lifecycle-events = off
@ -76,7 +78,9 @@ abstract class ClusterShardingRememberEntitiesNewExtractorSpecConfig(val mode: S
dir = target/ShardingRememberEntitiesNewExtractorSpec/sharding-ddata
map-size = 10 MiB
}
""").withFallback(MultiNodeClusterSpec.clusterConfig))
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
val roleConfig = ConfigFactory.parseString("""
akka.cluster.roles = [sharding]

View file

@ -51,7 +51,9 @@ abstract class ClusterShardingRememberEntitiesSpecConfig(val mode: String) exten
val second = role("second")
val third = role("third")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.cluster.auto-down-unreachable-after = 0s
@ -71,7 +73,9 @@ abstract class ClusterShardingRememberEntitiesSpecConfig(val mode: String) exten
dir = target/ShardingRememberEntitiesSpec/sharding-ddata
map-size = 10 MiB
}
""").withFallback(MultiNodeClusterSpec.clusterConfig))
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
nodeConfig(third)(ConfigFactory.parseString(s"""
akka.cluster.sharding.distributed-data.durable.lmdb {

View file

@ -9,9 +9,9 @@ import akka.cluster.sharding.ShardCoordinator.Internal.{ HandOff, ShardStopped }
import akka.cluster.sharding.ShardRegion.Passivate
import akka.cluster.sharding.ShardRegion.GetCurrentRegions
import akka.cluster.sharding.ShardRegion.CurrentRegions
import language.postfixOps
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.actor._
import akka.cluster.{ Cluster, MultiNodeClusterSpec }
@ -129,7 +129,9 @@ abstract class ClusterShardingSpecConfig(val mode: String, val entityRecoveryStr
val fifth = role("fifth")
val sixth = role("sixth")
commonConfig(ConfigFactory.parseString(s"""
commonConfig(
ConfigFactory
.parseString(s"""
akka.loglevel = INFO
akka.actor.provider = "cluster"
akka.remote.log-remote-lifecycle-events = off
@ -165,7 +167,21 @@ abstract class ClusterShardingSpecConfig(val mode: String, val entityRecoveryStr
}
}
akka.testconductor.barrier-timeout = 70s
""").withFallback(MultiNodeClusterSpec.clusterConfig))
# using Java serialization for the messages here because would be to much (unrelated)
# to show full Jackson serialization in docs (requires annotations because of envelope and such)
akka.actor.serialization-bindings {
"${ClusterShardingSpec.Increment.getClass.getName}" = java-test
"${ClusterShardingSpec.Decrement.getClass.getName}" = java-test
"${classOf[ClusterShardingSpec.Get].getName}" = java-test
"${classOf[ClusterShardingSpec.EntityEnvelope].getName}" = java-test
"${ClusterShardingSpec.Stop.getClass.getName}" = java-test
"${classOf[ClusterShardingSpec.CounterChanged].getName}" = java-test
}
""")
.withFallback(SharedLeveldbJournal.configToEnableJavaSerializationForTest)
.withFallback(MultiNodeClusterSpec.clusterConfig))
nodeConfig(sixth) {
ConfigFactory.parseString("""akka.cluster.roles = ["frontend"]""")
}

View file

@ -5,6 +5,7 @@
package akka.cluster.sharding
import scala.concurrent.duration._
import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.Address
@ -16,13 +17,14 @@ import akka.remote.testconductor.RoleName
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.remote.testkit.STMultiNodeSpec
import akka.serialization.jackson.CborSerializable
import akka.testkit._
import com.typesafe.config.ConfigFactory
import akka.util.ccompat._
@ccompatUsedUntil213
object MultiDcClusterShardingSpec {
sealed trait EntityMsg {
sealed trait EntityMsg extends CborSerializable {
def id: String
}
final case class Ping(id: String) extends EntityMsg