#2532 - Fixing PostRestart prematurely clearing out the fancy bits out of the InvocationHandler

This commit is contained in:
Viktor Klang 2012-09-20 12:54:17 +02:00
parent 2893b0f467
commit 2c3bc310a3
2 changed files with 20 additions and 9 deletions

View file

@ -193,6 +193,9 @@ object TypedActorSpec {
})
}
}
trait F { def f(pow: Boolean): Int }
class FI extends F { def f(pow: Boolean): Int = if (pow) throw new IllegalStateException("expected") else 1 }
}
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
@ -351,6 +354,21 @@ class TypedActorSpec extends AkkaSpec(TypedActorSpec.config)
}
}
"be restarted on failure" in {
filterEvents(EventFilter[IllegalStateException]("expected")) {
val t = newFooBar(Duration(2, "s"))
intercept[IllegalStateException] { t.failingOptionPigdog() }.getMessage must be === "expected"
t.optionPigdog() must be === Some("Pigdog")
mustStop(t)
val ta: F = TypedActor(system).typedActorOf(TypedProps[FI]())
intercept[IllegalStateException] { ta.f(true) }.getMessage must be === "expected"
ta.f(false) must be === 1
mustStop(ta)
}
}
"be able to support stacked traits for the interface part" in {
val t = newStacked()
t.notOverriddenStacked must be("foobar")

View file

@ -235,14 +235,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
* INTERNAL USE ONLY
*/
private[akka] class TypedActor[R <: AnyRef, T <: R](val proxyVar: AtomVar[R], createInstance: T) extends Actor {
val me = try {
TypedActor.selfReference set proxyVar.get
TypedActor.currentContext set context
createInstance
} finally {
TypedActor.selfReference set null
TypedActor.currentContext set null
}
val me = withContext[T](createInstance)
override def supervisorStrategy(): SupervisorStrategy = me match {
case l: Supervisor l.supervisorStrategy
@ -275,7 +268,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
override def preRestart(reason: Throwable, message: Option[Any]): Unit = withContext {
me match {
case l: PreRestart l.preRestart(reason, message)
case _ super.preRestart(reason, message)
case _ context.children foreach context.stop //Can't be super.preRestart(reason, message) since that would invoke postStop which would set the actorVar to DL and proxyVar to null
}
}