#3085 - Fixing so that option-returning TypedACtor calls return None

This commit is contained in:
Viktor Klang 2013-02-25 13:58:51 +01:00
parent eb057743d7
commit bb88aed56e
2 changed files with 11 additions and 2 deletions

View file

@ -324,6 +324,12 @@ class TypedActorSpec extends AkkaSpec(TypedActorSpec.config)
mustStop(t)
}
"be able to handle AskTimeoutException as None" taggedAs TimingTest in {
val t = newFooBar(200 millis)
t.joptionPigdog(600 millis) must be(JOption.none[String])
mustStop(t)
}
"be able to call methods returning Scala Options" taggedAs TimingTest in {
val t = newFooBar(1 second)
t.optionPigdog(100 millis).get must be("Pigdog")

View file

@ -23,6 +23,7 @@ import java.util.concurrent.TimeoutException
import java.util.concurrent.TimeUnit.MILLISECONDS
import java.io.ObjectStreamException
import java.lang.reflect.{ InvocationTargetException, Method, InvocationHandler, Proxy }
import akka.pattern.AskTimeoutException
/**
* A TypedActorFactory is something that can created TypedActor instances.
@ -421,8 +422,10 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
case m if m.returnsJOption || m.returnsOption
val f = ask(actor, m)(timeout)
(try { Await.ready(f, timeout.duration).value } catch { case _: TimeoutException None }) match {
case None | Some(Success(NullResponse)) if (m.returnsJOption) JOption.none[Any] else None
case Some(t: Try[_]) t.get.asInstanceOf[AnyRef]
case None | Some(Success(NullResponse)) | Some(Failure(_: AskTimeoutException))
if (m.returnsJOption) JOption.none[Any] else None
case Some(t: Try[_])
t.get.asInstanceOf[AnyRef]
}
case m Await.result(ask(actor, m)(timeout), timeout.duration) match {
case NullResponse null