Skip to content

Commit f4e988f

Browse files
committed
Usually de/serialize the response too
1 parent defcc57 commit f4e988f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

server/src/main/java/org/elasticsearch/cluster/coordination/PreVoteCollector.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
import org.elasticsearch.common.Nullable;
2727
import org.elasticsearch.common.collect.Tuple;
2828
import org.elasticsearch.common.component.AbstractComponent;
29+
import org.elasticsearch.common.io.stream.StreamInput;
2930
import org.elasticsearch.common.lease.Releasable;
3031
import org.elasticsearch.common.settings.Settings;
3132
import org.elasticsearch.threadpool.ThreadPool.Names;
3233
import org.elasticsearch.transport.TransportException;
3334
import org.elasticsearch.transport.TransportResponseHandler;
3435
import org.elasticsearch.transport.TransportService;
3536

37+
import java.io.IOException;
3638
import java.util.Set;
3739
import java.util.concurrent.atomic.AtomicBoolean;
3840
import java.util.function.LongConsumer;
@@ -127,6 +129,11 @@ void start(final Iterable<DiscoveryNode> broadcastNodes) {
127129
logger.debug("{} requesting pre-votes from {}", this, broadcastNodes);
128130
broadcastNodes.forEach(n -> transportService.sendRequest(n, REQUEST_PRE_VOTE_ACTION_NAME, preVoteRequest,
129131
new TransportResponseHandler<PreVoteResponse>() {
132+
@Override
133+
public PreVoteResponse read(StreamInput in) throws IOException {
134+
return new PreVoteResponse(in);
135+
}
136+
130137
@Override
131138
public void handleResponse(PreVoteResponse response) {
132139
handlePreVoteResponse(response, n);

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.test.transport;
2121

22-
import org.elasticsearch.ElasticsearchException;
2322
import org.elasticsearch.action.ActionListener;
2423
import org.elasticsearch.cluster.node.DiscoveryNode;
2524
import org.elasticsearch.common.Nullable;
@@ -91,7 +90,18 @@ public TransportService createTransportService(Settings settings, ThreadPool thr
9190
public void handleResponse(final long requestId, final TransportResponse response) {
9291
final TransportResponseHandler transportResponseHandler = responseHandlers.onResponseReceived(requestId, listener);
9392
if (transportResponseHandler != null) {
94-
transportResponseHandler.handleResponse(response);
93+
final TransportResponse deliveredResponse;
94+
if (rarely()) {
95+
deliveredResponse = response;
96+
} else {
97+
try (BytesStreamOutput output = new BytesStreamOutput()) {
98+
response.writeTo(output);
99+
deliveredResponse = transportResponseHandler.read(output.bytes().streamInput());
100+
} catch (IOException | UnsupportedOperationException e) {
101+
throw new AssertionError("failed to serialize/deserialize response " + response, e);
102+
}
103+
}
104+
transportResponseHandler.handleResponse(deliveredResponse);
95105
}
96106
}
97107

@@ -126,7 +136,7 @@ public void handleRemoteError(final long requestId, final Throwable t) {
126136
output.writeException(t);
127137
remoteException = new RemoteTransportException("remote failure", output.bytes().streamInput().readException());
128138
} catch (IOException ioException) {
129-
throw new ElasticsearchException("failed to serialize/deserialize supplied exception " + t, ioException);
139+
throw new AssertionError("failed to serialize/deserialize supplied exception " + t, ioException);
130140
}
131141
}
132142
this.handleError(requestId, remoteException);

0 commit comments

Comments
 (0)