Skip to content

Commit ba317b4

Browse files
authored
Do not deserialize back BytesTransportRequest to clone a request in MockTransportService (elastic#89926) (elastic#89936)
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 dc8abe1 commit ba317b4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 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,21 @@ 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+
// This is only needed for the BwC for JOIN_VALIDATE_ACTION_NAME and can be removed in the next major
514+
assert Version.CURRENT.major == Version.V_7_17_0.major + 1;
515+
clonedRequest = new BytesTransportRequest(bStream.bytes().streamInput());
516+
} else {
517+
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
518+
clonedRequest = reg.newRequest(bStream.bytes().streamInput());
519+
}
520+
assert clonedRequest.getClass().equals(request.getClass()) : clonedRequest + " vs " + request;
509521

510522
final RunOnce runnable = new RunOnce(new AbstractRunnable() {
511523
@Override

0 commit comments

Comments
 (0)