Skip to content

Commit c358446

Browse files
committed
Do not deserialize back BytesTransportRequest to clone a request in MockTransportService
Some handlers, such as JOIN_VALIDATE_ACTION_NAME, deserialize a BytesTransportRequest into a different class that cannot be serialized. This commit changes that behaviour and directly clones the BytesTransportRequest instead of relying on the transport handler. Closes elastic#88120
1 parent 397df7d commit c358446

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.elasticsearch.test.tasks.MockTaskManager;
3838
import org.elasticsearch.threadpool.ThreadPool;
3939
import org.elasticsearch.tracing.Tracer;
40+
import org.elasticsearch.transport.BytesTransportRequest;
4041
import org.elasticsearch.transport.ClusterConnectionManager;
4142
import org.elasticsearch.transport.ConnectTransportException;
4243
import org.elasticsearch.transport.ConnectionProfile;
@@ -502,10 +503,18 @@ public void sendRequest(
502503
}
503504

504505
// poor mans request cloning...
505-
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
506506
BytesStreamOutput bStream = new BytesStreamOutput();
507507
request.writeTo(bStream);
508-
final TransportRequest clonedRequest = reg.newRequest(bStream.bytes().streamInput());
508+
final TransportRequest clonedRequest;
509+
if (request instanceof BytesTransportRequest) {
510+
// Some request handlers read back a BytesTransportRequest
511+
// into a different class that cannot be re-serialized (i.e. JOIN_VALIDATE_ACTION_NAME),
512+
// in those cases we just copy the raw bytes back to a BytesTransportRequest.
513+
clonedRequest = new BytesTransportRequest(bStream.bytes().streamInput());
514+
} else {
515+
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
516+
clonedRequest = reg.newRequest(bStream.bytes().streamInput());
517+
}
509518

510519
final RunOnce runnable = new RunOnce(new AbstractRunnable() {
511520
@Override

0 commit comments

Comments
 (0)