本文整理汇总了Scala中java.io.NotSerializableException类的典型用法代码示例。如果您正苦于以下问题:Scala NotSerializableException类的具体用法?Scala NotSerializableException怎么用?Scala NotSerializableException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NotSerializableException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PersistenceMessageSerializerSpec
//设置package包名称以及导入依赖的类
package com.lightbend.lagom.internal.javadsl.persistence.protobuf
import java.io.NotSerializableException
import scala.concurrent.duration._
import akka.actor.ExtendedActorSystem
import akka.serialization.SerializationExtension
import com.lightbend.lagom.internal.persistence.cluster.ClusterDistribution.EnsureActive
import com.lightbend.lagom.persistence.ActorSystemSpec
import com.lightbend.lagom.javadsl.persistence.CommandEnvelope
import com.lightbend.lagom.javadsl.persistence.PersistentEntity.InvalidCommandException
import com.lightbend.lagom.javadsl.persistence.PersistentEntity.PersistException
import com.lightbend.lagom.javadsl.persistence.PersistentEntity.UnhandledCommandException
import com.lightbend.lagom.javadsl.persistence.PersistentEntityRef
import com.lightbend.lagom.javadsl.persistence.TestEntity
class PersistenceMessageSerializerSpec extends ActorSystemSpec {
val serializer = new PersistenceMessageSerializer(system.asInstanceOf[ExtendedActorSystem])
def checkSerialization(obj: AnyRef): Unit = {
// check that it is configured
SerializationExtension(system).serializerFor(obj.getClass).getClass should be(classOf[PersistenceMessageSerializer])
// verify serialization-deserialization round trip
val blob = serializer.toBinary(obj)
val obj2 = serializer.fromBinary(blob, serializer.manifest(obj))
obj2 should be(obj)
}
"PersistenceMessageSerializer" must {
"serialize CommandEnvelope" in {
checkSerialization(CommandEnvelope("entityId", TestEntity.Add.of("a")))
}
"serialize EnsureActive" in {
checkSerialization(EnsureActive("foo"))
}
"serialize InvalidCommandException" in {
checkSerialization(InvalidCommandException("wrong"))
}
"serialize UnhandledCommandException" in {
checkSerialization(UnhandledCommandException("unhandled"))
}
"serialize PersistException" in {
checkSerialization(PersistException("not stored"))
}
"not serialize PersistentEntityRef" in {
intercept[NotSerializableException] {
SerializationExtension(system).serialize(new PersistentEntityRef[String]("abc", system.deadLetters, system, 5.seconds)).get
}
}
}
}