Github user BryanCutler commented on the pull request:
https://github.com/apache/spark/pull/6205#issuecomment-106899655
Hey guys, I've been playing around with making the futures fail before
calling await, here is a test case that does it:
```scala
test("Future failure with RpcTimeout") {
class EchoActor extends Actor {
def receive: Receive = {
case msg =>
Thread.sleep(50)
sender() ! msg
}
}
val system = ActorSystem("EchoSystem")
val echoActor = system.actorOf(Props(new EchoActor), name = "echoA")
val timeout = new RpcTimeout(50 millis, "spark.rpc.short.timeout")
val fut = echoActor.ask("hello")(10 millis).mapTo[String].recover {
case te: TimeoutException => throw timeout.amend(te)
}
fut.onFailure {
case te: TimeoutException => println("failed with timeout exception")
}
fut.onComplete {
case Success(str) => println("future success")
case Failure(ex) => println("future failure")
}
println("sleeping")
Thread.sleep(50)
println("Future complete: " + fut.isCompleted.toString() + ", " +
fut.value.toString())
println("Caught TimeoutException: " +
intercept[TimeoutException] {
//timeout.awaitResult(fut) // will print RpcTimeout description
twice
Await.result(fut, 10 millis)
}.getMessage()
)
}
```
If we use `recover`, then when a future fails we can check for a
`TimeoutException` and then re-raise the exception with our modified message as
before, and we wouldn't need to do it in `Await.result` anymore. It also
doesn't change the type of `Future` returned. I kind of think this is a better
solution because it would handle all cases of `Future` timeouts regardless if
`Await.result` is used. What do you guys think?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]