Making sure that ActorCell isn't serializable

This commit is contained in:
Viktor Klang 2011-12-08 16:07:03 +01:00
parent 4803ba517c
commit 712805baec
3 changed files with 22 additions and 4 deletions

View file

@ -7,10 +7,9 @@ package akka.serialization
import akka.serialization.Serialization._
import scala.reflect._
import akka.testkit.AkkaSpec
import akka.actor.{ ActorSystem, ActorSystemImpl }
import java.io.{ ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream }
import akka.actor.DeadLetterActorRef
import com.typesafe.config.ConfigFactory
import akka.actor._
import java.io._
object SerializeSpec {
@ -94,6 +93,22 @@ class SerializeSpec extends AkkaSpec(SerializeSpec.serializationConf) {
}
}
"not serialize ActorCell" in {
val a = system.actorOf(Props(new Actor {
def receive = {
case o: ObjectOutputStream
try {
o.writeObject(this)
} catch {
case _: NotSerializableException testActor ! "pass"
}
}
}))
a ! new ObjectOutputStream(new ByteArrayOutputStream())
expectMsg("pass")
a.stop
}
"serialize DeadLetterActorRef" in {
val outbuf = new ByteArrayOutputStream()
val out = new ObjectOutputStream(outbuf)

View file

@ -206,7 +206,6 @@ trait Actor {
* [[akka.actor.UntypedActorContext]], which is the Java API of the actor
* context.
*/
@transient
protected[akka] implicit val context: ActorContext = {
val contextStack = ActorCell.contextStack.get

View file

@ -12,6 +12,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS
import akka.event.Logging.{ Debug, Warning, Error }
import akka.util.{ Duration, Helpers }
import akka.japi.Procedure
import java.io.{ NotSerializableException, ObjectOutputStream }
/**
* The actor context - the view of the actor cell from the actor.
@ -602,4 +603,7 @@ private[akka] final class ActorCell(
lookupAndSetField(a.getClass, a, "self", self)
}
}
final protected def writeObject(o: ObjectOutputStream): Unit =
throw new NotSerializableException("ActorCell/ActorContext is not serializable!")
}