This is an automated email from the ASF dual-hosted git repository.
zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new 603060a2ec [CELEBORN-2517] Avoid redundant GetReducerFileGroupResponse
serialization when the broadcast is reusable
603060a2ec is described below
commit 603060a2ec19a569f087897d57976b0147182144
Author: wang-haihua <[email protected]>
AuthorDate: Thu Nov 5 00:41:24 2026 +0800
[CELEBORN-2517] Avoid redundant GetReducerFileGroupResponse serialization
when the broadcast is reusable
### What changes were proposed in this pull request?
When the `GetReducerFileGroupResponse` broadcast is enabled,
`ReducePartitionCommitHandler.replyGetReducerFileGroup` now looks up the live
broadcast before building anything: if the shuffle already has one, the reply
is that handle and the response is not rebuilt. It also stops serializing the
response merely to measure it — the transport message has to be built anyway,
so the threshold is compared against its payload length.
This adds a lookup callback
(`LifecycleManager.cachedBroadcastGetReducerFileGroupResponse` →
`SparkUtils.getCachedSerializedGetReducerFileGroupResponse`) alongside the
existing broadcast/invalidate callbacks.
### Why are the changes needed?
The driver caches the serialized response in `getReducerFileGroupRpcCache`
(`celeborn.client.rpc.cache.expireTime`, default 15s, `maximumSize` 256). When
that entry expires or is evicted while the broadcast is still alive, the cache
loader rebuilds the whole response, serializes it to compare with
`getReducerFileGroup.broadcast.miniSize`, and hands it to the broadcast
callback — which finds the shuffle in
`SparkUtils.getReducerFileGroupResponseBroadcasts` and returns the cached
handle [...]
Measured on a synthetic metadata test (165366 mappers, 10000 reducers,
24608-byte map-id bitmap per partition, 166 chunk offsets per file), driver
`-Xmx4g`, `broadcast.miniSize=0`, `rpc.cache.expireTime=15s`, three requests
20s apart:
| | before | after |
| --- | --- | --- |
| full response builds (3 requests) | 3 | 1 |
| heap used entering request 3 | 2070 MiB | 855 MiB |
| heap growth across one cache miss | +1310 MiB | +7 MiB |
| request latency on a cache miss | 1538 ms / 1759 ms | 5 ms / 5 ms |
The response payload is 243.7 MiB here, and one rebuild leaves ~1.3 GiB of
transient garbage because Java serialization grows its `ByteArrayOutputStream`
by doubling and copying.
In addition, a driver OOM has been observed with a ~1.21 GiB allocation in
`ByteArrayOutputStream.grow` on this path.
<img width="1512" height="847" alt="ME1793268522791"
src="https://github.com/user-attachments/assets/b5fbf5c9-8539-447b-8e7e-f52cace0a6a9"
/>
Reusing the handle produces the same bytes the broadcast callback would
have returned, so this removes work rather than changing the reply. The
broadcast outlives the cache entry: both are torn down together in
`LifecycleManager.removeExpiredShuffle`.
See [CELEBORN-2517](https://issues.apache.org/jira/browse/CELEBORN-2517)
for full analysis.
### Does this PR resolve a correctness bug?
- [ ] Yes
### Does this PR introduce _any_ user-facing change?
- [x] Yes
No protocol or configuration change; driver-side only. One behavioral note:
the
broadcast previously compared
`ByteBufferOutputStream.toByteBuffer.capacity()`, which is the length
of the doubling-grown backing array rather than of the message. That made
the effective
threshold lower than the configured one. The comparison now
uses the real payload length, so with the 512 KiB default, responses whose
payload falls
roughly between 256 KiB and 512 KiB are replied directly instead of being
broadcast.
Deployments that want the previous effective threshold can halve
`celeborn.client.spark.shuffle.getReducerFileGroup.broadcast.miniSize`.
### How was this patch tested?
New unit tests in `ReducePartitionCommitHandlerSuite`, which drive
`replyGetReducerFileGroup` through a mocked `RemoteNettyRpcCallContext` and set
`celeborn.client.rpc.cache.expireTime` to 0 so every request runs the rpc cache
loader deterministically, without sleeping:
- a live broadcast is reused on a cache miss: the handle comes back
unchanged, the broadcast-creation callback is not invoked again, and the
response is not rebuilt.
- an invalidated broadcast falls back to building the response and
broadcasting it anew.
- a broadcast that cannot be created falls back to replying with the whole
response.
- broadcasting disabled never consults the lookup and replies with the
whole response.
The reuse case asserts on `getMapperAttempts`, which only the full-response
path reads, so moving the lookup after the response is built fails the test.
The fallback cases decode the replied `TransportMessage` and assert the status,
mapper attempts and empty broadcast field, so an empty or truncated response
fails the test too. Both were checked against deliberately broken variants of
the handler, along with reverting the fix entirely.
Also verified against the existing broadcast coverage:
`SparkUtilsSuite."serialize/deserialize GetReducerFileGroupResponse with
broadcast"` and `CelebornSortSuite."celeborn spark integration test -
GetReducerFileGroupResponse broadcast"`.
End-to-end on a test cluster with the synthetic metadata test above, run
twice with the same configuration and only the client jar swapped. The
unpatched run rebuilt the response on both cache misses
(`GetReducerFileGroupResponse size ...`); the patched run logged `reuses the
live GetReducerFileGroupResponse broadcast of 807 bytes.` on both, returned the
identical handle, and produced the numbers in the table.
Closes #3915 from
wang-haihua/avoid-redundant-reducer-file-group-serialization.
Authored-by: wang-haihua <[email protected]>
Signed-off-by: zhengtao <[email protected]>
AI-Contributed/Feature: 0/73
AI-Contributed/UT: 0/188
---
.../shuffle/celeborn/SparkShuffleManager.java | 2 +
.../apache/spark/shuffle/celeborn/SparkUtils.java | 13 ++
.../apache/celeborn/client/LifecycleManager.scala | 15 ++
.../commit/ReducePartitionCommitHandler.scala | 43 +++--
.../commit/ReducePartitionCommitHandlerSuite.scala | 188 ++++++++++++++++++++-
5 files changed, 249 insertions(+), 12 deletions(-)
diff --git
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
index b731d4923f..1103355b8a 100644
---
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
+++
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkShuffleManager.java
@@ -248,6 +248,8 @@ public class SparkShuffleManager implements ShuffleManager {
}
if (celebornConf.getReducerFileGroupBroadcastEnabled()) {
+
lifecycleManager.registerCachedBroadcastGetReducerFileGroupResponseCallback(
+ SparkUtils::getCachedSerializedGetReducerFileGroupResponse);
lifecycleManager.registerBroadcastGetReducerFileGroupResponseCallback(
(shuffleId, getReducerFileGroupResponse) ->
SparkUtils.serializeGetReducerFileGroupResponse(
diff --git
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java
index 0ad8301b16..500b4f032e 100644
---
a/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java
+++
b/client-spark/spark-3/src/main/java/org/apache/spark/shuffle/celeborn/SparkUtils.java
@@ -623,6 +623,19 @@ public class SparkUtils {
public static Map<Integer, Tuple2<Broadcast<TransportMessage>, byte[]>>
getReducerFileGroupResponseBroadcasts = JavaUtils.newConcurrentHashMap();
+ /** The serialized handle of the shuffle's existing broadcast, or null if it
has none. */
+ public static byte[] getCachedSerializedGetReducerFileGroupResponse(Integer
shuffleId) {
+ return shuffleBroadcastLock.withLock(
+ shuffleId,
+ () -> {
+ Tuple2<Broadcast<TransportMessage>, byte[]>
cachedSerializeGetReducerFileGroupResponse =
+ getReducerFileGroupResponseBroadcasts.get(shuffleId);
+ return cachedSerializeGetReducerFileGroupResponse != null
+ ? cachedSerializeGetReducerFileGroupResponse._2
+ : null;
+ });
+ }
+
public static byte[] serializeGetReducerFileGroupResponse(
Integer shuffleId, GetReducerFileGroupResponse response) {
SparkContext sparkContext =
SparkContext$.MODULE$.getActive().getOrElse(null);
diff --git
a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
index 7122df06a3..005806a510 100644
--- a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
+++ b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
@@ -2294,6 +2294,14 @@ class LifecycleManager(val appUniqueId: String, val
conf: CelebornConf) extends
broadcastGetReducerFileGroupResponseCallback = Some(call)
}
+ @volatile private var cachedBroadcastGetReducerFileGroupResponseCallback
+ : Option[function.Function[Integer, Array[Byte]]] =
+ None
+ def registerCachedBroadcastGetReducerFileGroupResponseCallback(
+ call: function.Function[Integer, Array[Byte]]): Unit = {
+ cachedBroadcastGetReducerFileGroupResponseCallback = Some(call)
+ }
+
@volatile private var invalidatedBroadcastCallback:
Option[Consumer[Integer]] =
None
def registerInvalidatedBroadcastCallback(call: Consumer[Integer]): Unit = {
@@ -2357,6 +2365,13 @@ class LifecycleManager(val appUniqueId: String, val
conf: CelebornConf) extends
}
}
+ def cachedBroadcastGetReducerFileGroupResponse(shuffleId: Int):
Option[Array[Byte]] = {
+ cachedBroadcastGetReducerFileGroupResponseCallback match {
+ case Some(c) => Option(c.apply(shuffleId))
+ case _ => None
+ }
+ }
+
private def invalidatedBroadcastGetReducerFileGroupResponse(shuffleId: Int):
Unit = {
invalidatedBroadcastCallback match {
case Some(c) => c.accept(shuffleId)
diff --git
a/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
b/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
index 62c03a3877..8a34d0d2de 100644
---
a/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
+++
b/client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala
@@ -38,6 +38,7 @@ import org.apache.celeborn.common.internal.Logging
import org.apache.celeborn.common.meta.ShufflePartitionLocationInfo
import org.apache.celeborn.common.network.protocol.SerdeVersion
import org.apache.celeborn.common.protocol.{PartitionLocation, PartitionType,
PbGetStageEndResponse}
+import org.apache.celeborn.common.protocol.message.ControlMessages
import
org.apache.celeborn.common.protocol.message.ControlMessages.GetReducerFileGroupResponse
import org.apache.celeborn.common.protocol.message.StatusCode
import org.apache.celeborn.common.rpc.RpcCallContext
@@ -501,10 +502,23 @@ class ReducePartitionCommitHandler(
context.reply(response)
} else {
+ val nettyEnv = context.asInstanceOf[RemoteNettyRpcCallContext].nettyEnv
val cachedMsg = getReducerFileGroupRpcCache.get(
shuffleId,
new Callable[ByteBuffer]() {
override def call(): ByteBuffer = {
+ // Reuse a live broadcast before building anything
+ reusableBroadcast(shuffleId) match {
+ case Some(broadcastBytes) =>
+ logInfo(s"Shuffle $shuffleId reuses the live
GetReducerFileGroupResponse" +
+ s" broadcast of ${broadcastBytes.length} bytes.")
+ return nettyEnv.serialize(GetReducerFileGroupResponse(
+ StatusCode.SUCCESS,
+ broadcast = broadcastBytes,
+ serdeVersion = serdeVersion))
+ case None =>
+ }
+
val returnedMsg = GetReducerFileGroupResponse(
StatusCode.SUCCESS,
reducerFileGroupsMap.getOrDefault(shuffleId,
JavaUtils.newConcurrentHashMap()),
@@ -515,27 +529,26 @@ class ReducePartitionCommitHandler(
new util.HashMap[String, LocationPushFailedBatches]()),
serdeVersion = serdeVersion)
- val serializedMsg =
-
context.asInstanceOf[RemoteNettyRpcCallContext].nettyEnv.serialize(returnedMsg)
- logInfo(
- s"Shuffle $shuffleId GetReducerFileGroupResponse size " +
serializedMsg.capacity())
+ // Size the payload that is sent, not a throwaway serialization
of the response.
+ val transportMsg =
ControlMessages.toTransportMessage(returnedMsg)
+ val responseSize = transportMsg.getPayload.length
+ logInfo(s"Shuffle $shuffleId GetReducerFileGroupResponse size
$responseSize")
if (getReducerFileGroupResponseBroadcastEnabled &&
- serializedMsg.capacity() >=
getReducerFileGroupResponseBroadcastMiniSize) {
+ responseSize >= getReducerFileGroupResponseBroadcastMiniSize) {
val broadcastMsg = broadcastGetReducerFileGroup(shuffleId,
returnedMsg)
- if (broadcastMsg != returnedMsg) {
- val serializedBroadcastMsg =
-
context.asInstanceOf[RemoteNettyRpcCallContext].nettyEnv.serialize(broadcastMsg)
+ if (broadcastMsg ne returnedMsg) {
+ val serializedBroadcastMsg = nettyEnv.serialize(broadcastMsg)
logInfo(s"Shuffle $shuffleId GetReducerFileGroupResponse
size" +
- s" ${serializedMsg.capacity()} reached the broadcast
threshold" +
+ s" $responseSize reached the broadcast threshold" +
s" $getReducerFileGroupResponseBroadcastMiniSize," +
s" the broadcast response size is
${serializedBroadcastMsg.capacity()}.")
serializedBroadcastMsg
} else {
- serializedMsg
+ nettyEnv.serialize(transportMsg)
}
} else {
- serializedMsg
+ nettyEnv.serialize(transportMsg)
}
}
})
@@ -544,6 +557,14 @@ class ReducePartitionCommitHandler(
}
}
+ private def reusableBroadcast(shuffleId: Int): Option[Array[Byte]] = {
+ if (getReducerFileGroupResponseBroadcastEnabled) {
+
lifecycleManager.cachedBroadcastGetReducerFileGroupResponse(shuffleId).filter(_.nonEmpty)
+ } else {
+ None
+ }
+ }
+
private def broadcastGetReducerFileGroup(
shuffleId: Int,
response: GetReducerFileGroupResponse): GetReducerFileGroupResponse = {
diff --git
a/client/src/test/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandlerSuite.scala
b/client/src/test/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandlerSuite.scala
index bca906f341..1b53de3262 100644
---
a/client/src/test/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandlerSuite.scala
+++
b/client/src/test/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandlerSuite.scala
@@ -17,9 +17,16 @@
package org.apache.celeborn.client.commit
+import java.nio.ByteBuffer
import java.util.concurrent.{ScheduledExecutorService, ThreadPoolExecutor}
-import org.mockito.Mockito.mock
+import scala.collection.JavaConverters._
+
+import org.mockito.ArgumentCaptor
+import org.mockito.ArgumentMatchers.{any, anyInt, eq => eqTo}
+import org.mockito.Mockito.{mock, never, spy, times, verify, when}
+import org.mockito.invocation.InvocationOnMock
+import org.mockito.stubbing.Answer
import org.apache.celeborn.CelebornFunSuite
import org.apache.celeborn.client.{LifecycleManager, WorkerStatusTracker}
@@ -27,7 +34,12 @@ import
org.apache.celeborn.client.CommitManager.CommittedPartitionInfo
import org.apache.celeborn.client.LifecycleManager.ShuffleAllocatedWorkers
import org.apache.celeborn.common.CelebornConf
import org.apache.celeborn.common.meta.{ShufflePartitionLocationInfo,
WorkerInfo}
+import org.apache.celeborn.common.network.client.RpcResponseCallback
+import org.apache.celeborn.common.network.protocol.{SerdeVersion,
TransportMessage}
+import org.apache.celeborn.common.protocol.message.ControlMessages
+import
org.apache.celeborn.common.protocol.message.ControlMessages.GetReducerFileGroupResponse
import org.apache.celeborn.common.protocol.message.StatusCode
+import org.apache.celeborn.common.rpc.netty.{NettyRpcEnv,
RemoteNettyRpcCallContext}
import org.apache.celeborn.common.util.JavaUtils
class ReducePartitionCommitHandlerSuite extends CelebornFunSuite {
@@ -64,6 +76,180 @@ class ReducePartitionCommitHandlerSuite extends
CelebornFunSuite {
assert(!handler.isStageDataLost(shuffleId + 1))
}
+ test("reuse a live broadcast instead of rebuilding the response on an rpc
cache miss") {
+ val cache = new BroadcastCache
+ val handler = spy[ReducePartitionCommitHandler](newBroadcastHandler(cache))
+ val remote = newRemoteContext()
+
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+ val handle = cache.currentHandle
+
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+
+ // The second miss must neither rebuild the response nor create another
broadcast.
+ verify(handler, times(1)).getMapperAttempts(shuffleId)
+ verify(cache.lifecycleManager,
times(1)).broadcastGetReducerFileGroupResponse(
+ eqTo(shuffleId),
+ any(classOf[GetReducerFileGroupResponse]))
+
+ serializedMessagesOf(remote, 2).foreach {
+ case response: GetReducerFileGroupResponse =>
+ assert(response.status == StatusCode.SUCCESS)
+ assert(response.broadcast.sameElements(handle))
+ assert(response.fileGroup.isEmpty)
+ assert(response.attempts.isEmpty)
+ case other => fail(s"expected a broadcast response, got
${other.getClass.getName}")
+ }
+ }
+
+ test("rebuild the response on an rpc cache miss after the broadcast was
invalidated") {
+ val cache = new BroadcastCache
+ val handler = spy[ReducePartitionCommitHandler](newBroadcastHandler(cache))
+ val remote = newRemoteContext()
+
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+ val firstHandle = cache.currentHandle
+
+ cache.invalidate()
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+
+ // Nothing to reuse, so the response is built a second time and broadcast
anew.
+ verify(handler, times(2)).getMapperAttempts(shuffleId)
+ verify(cache.lifecycleManager,
times(2)).broadcastGetReducerFileGroupResponse(
+ eqTo(shuffleId),
+ any(classOf[GetReducerFileGroupResponse]))
+
+ val secondHandle = cache.currentHandle
+ assert(!secondHandle.sameElements(firstHandle))
+ val replies =
+ serializedMessagesOf(remote,
2).map(_.asInstanceOf[GetReducerFileGroupResponse])
+ assert(replies.head.broadcast.sameElements(firstHandle))
+ assert(replies.last.broadcast.sameElements(secondHandle))
+ }
+
+ test("reply with the whole response when the broadcast cannot be created") {
+ val cache = new BroadcastCache(canCreate = false)
+ val handler = newBroadcastHandler(cache)
+ val remote = newRemoteContext()
+
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+
+ verify(cache.lifecycleManager,
times(1)).broadcastGetReducerFileGroupResponse(
+ eqTo(shuffleId),
+ any(classOf[GetReducerFileGroupResponse]))
+ assertWholeResponse(serializedMessagesOf(remote, 1).head)
+ }
+
+ test("reply with the whole response when broadcasting is disabled") {
+ val cache = new BroadcastCache
+ val handler = newBroadcastHandler(cache, broadcastEnabled = false)
+ val remote = newRemoteContext()
+
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+ handler.handleGetReducerFileGroup(remote.context, shuffleId,
SerdeVersion.V1)
+
+ verify(cache.lifecycleManager,
never()).cachedBroadcastGetReducerFileGroupResponse(anyInt())
+ verify(cache.lifecycleManager,
never()).broadcastGetReducerFileGroupResponse(
+ anyInt(),
+ any(classOf[GetReducerFileGroupResponse]))
+ serializedMessagesOf(remote, 2).foreach(assertWholeResponse)
+ }
+
+ /** Asserts that a serialized message carries this shuffle's file group, not
a broadcast. */
+ private def assertWholeResponse(message: Any): Unit = {
+ assert(message.isInstanceOf[TransportMessage], s"expected a transport
message, got $message")
+ val response = ControlMessages
+ .fromTransportMessage(message.asInstanceOf[TransportMessage])
+ .asInstanceOf[GetReducerFileGroupResponse]
+ assert(response.status == StatusCode.SUCCESS)
+ assert(response.attempts.sameElements(Array(-1, -1)))
+ assert(response.broadcast.isEmpty)
+ }
+
+ /**
+ * Stands in for SparkUtils' broadcast cache: creating a broadcast stores a
new handle and
+ * returns it, a lookup returns whatever is stored, and invalidate() drops
it.
+ */
+ private class BroadcastCache(canCreate: Boolean = true) {
+ private var handle: Array[Byte] = _
+ private var created = 0
+
+ val lifecycleManager: LifecycleManager = {
+ val manager = mock(classOf[LifecycleManager])
+ when(manager.broadcastGetReducerFileGroupResponse(
+ anyInt(),
+ any(classOf[GetReducerFileGroupResponse]))).thenAnswer(
+ new Answer[Option[Array[Byte]]] {
+ override def answer(invocation: InvocationOnMock):
Option[Array[Byte]] = {
+ if (!canCreate) {
+ None
+ } else {
+ created += 1
+ handle = s"broadcast-handle-$created".getBytes()
+ Some(handle)
+ }
+ }
+ })
+
when(manager.cachedBroadcastGetReducerFileGroupResponse(anyInt())).thenAnswer(
+ new Answer[Option[Array[Byte]]] {
+ override def answer(invocation: InvocationOnMock):
Option[Array[Byte]] = Option(handle)
+ })
+ manager
+ }
+
+ def invalidate(): Unit = handle = null
+
+ def currentHandle: Array[Byte] = handle
+ }
+
+ private def newBroadcastHandler(
+ cache: BroadcastCache,
+ broadcastEnabled: Boolean = true): ReducePartitionCommitHandler = {
+ val conf = new CelebornConf()
+
.set(CelebornConf.CLIENT_SHUFFLE_GET_REDUCER_FILE_GROUP_BROADCAST_ENABLED,
broadcastEnabled)
+
.set(CelebornConf.CLIENT_SHUFFLE_GET_REDUCER_FILE_GROUP_BROADCAST_MINI_SIZE, 0L)
+ .set(CelebornConf.CLIENT_RPC_CACHE_EXPIRE_TIME, 0L)
+ val handler = new ReducePartitionCommitHandler(
+ "test-app",
+ conf,
+ new ShuffleAllocatedWorkers(),
+ new CommittedPartitionInfo(),
+ new WorkerStatusTracker(conf, null),
+ mock(classOf[ThreadPoolExecutor]),
+ mock(classOf[ScheduledExecutorService]),
+ cache.lifecycleManager)
+ handler.registerShuffle(shuffleId, 2, isSegmentGranularityVisible = false,
2)
+ handler.setStageEnd(shuffleId)
+ handler
+ }
+
+ /** A remote rpc context with the serialized reply wired back to its
callback. */
+ private class RemoteContext {
+ val serialized: ByteBuffer = ByteBuffer.wrap("serialized-reply".getBytes())
+ val callback: RpcResponseCallback = mock(classOf[RpcResponseCallback])
+ val nettyEnv: NettyRpcEnv = {
+ val env = mock(classOf[NettyRpcEnv])
+ when(env.serialize(any())).thenReturn(serialized)
+ env
+ }
+ val context: RemoteNettyRpcCallContext = {
+ val ctx = mock(classOf[RemoteNettyRpcCallContext])
+ when(ctx.nettyEnv).thenReturn(nettyEnv)
+ when(ctx.callback).thenReturn(callback)
+ ctx
+ }
+ }
+
+ private def newRemoteContext(): RemoteContext = new RemoteContext
+
+ /** The messages handed to the rpc env for serialization, once each reply
was sent back. */
+ private def serializedMessagesOf(remote: RemoteContext, count: Int):
Seq[Any] = {
+ verify(remote.callback, times(count)).onSuccess(remote.serialized)
+ val messages = ArgumentCaptor.forClass(classOf[Any])
+ verify(remote.nettyEnv, times(count)).serialize(messages.capture())
+ messages.getAllValues.asScala.toList
+ }
+
private def newHandler(
excludedWorker: WorkerInfo,
detectionEnabled: Boolean = true,