Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit 2206b4d

Browse files
committed
[SPARK-6980] Added unit test for ask then immediat awaitReply
1 parent 1b9beab commit 2206b4d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

core/src/test/scala/org/apache/spark/rpc/akka/AkkaRpcEnvSuite.scala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,37 @@ class AkkaRpcEnvSuite extends RpcEnvSuite {
8787

8888
assert(result.nonEmpty)
8989

90-
// Ask with delayed response
90+
// Ask with a delayed response and wait for response immediately that should timeout
91+
fut = sleepyActor.ask("doh")(timeout.duration).mapTo[String]
92+
val msg1 =
93+
intercept[RpcTimeoutException] {
94+
timeout.awaitResult(fut)
95+
}.getMessage()
96+
97+
assert(msg1.contains(shortProp))
98+
99+
// Ask with delayed response using addMessageIfTimeout in recover callback
91100
fut = sleepyActor.ask("goodbye")(timeout.duration).mapTo[String].
92101
recover(timeout.addMessageIfTimeout)
93102

94103
// Allow future to complete with failure using plain Await.result, this will return
95-
// once the future is complete
96-
val msg1 =
104+
// once the future is complete to verify addMessageIfTimeout was invoked
105+
val msg2 =
97106
intercept[RpcTimeoutException] {
98107
Await.result(fut, 200 millis)
99108
}.getMessage()
100109

101-
assert(msg1.contains(shortProp))
110+
assert(msg2.contains(shortProp))
102111

103112
// Use RpcTimeout.awaitResult to process Future, since it has already failed with
104113
// RpcTimeoutException, the same exception should be thrown
105-
val msg2 =
114+
val msg3 =
106115
intercept[RpcTimeoutException] {
107116
timeout.awaitResult(fut)
108117
}.getMessage()
109118

110119
// Ensure description is not in message twice after addMessageIfTimeout and awaitResult
111-
assert(shortProp.r.findAllIn(msg2).length === 1)
120+
assert(shortProp.r.findAllIn(msg3).length === 1)
112121

113122
} finally {
114123
system.shutdown()

0 commit comments

Comments
 (0)