Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused ConnectTransportException#node #80944

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.transport;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand All @@ -16,8 +17,6 @@

public class ConnectTransportException extends ActionTransportException {

private final DiscoveryNode node;

public ConnectTransportException(DiscoveryNode node, String msg) {
this(node, msg, null, null);
}
Expand All @@ -32,21 +31,20 @@ public ConnectTransportException(DiscoveryNode node, String msg, Throwable cause

public ConnectTransportException(DiscoveryNode node, String msg, String action, Throwable cause) {
super(node == null ? null : node.getName(), node == null ? null : node.getAddress(), action, msg, cause);
this.node = node;
}

public ConnectTransportException(StreamInput in) throws IOException {
super(in);
node = in.readOptionalWriteable(DiscoveryNode::new);
if (in.getVersion().before(Version.V_8_1_0)) {
in.readOptionalWriteable(DiscoveryNode::new);
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalWriteable(node);
}

public DiscoveryNode node() {
return node;
if (out.getVersion().before(Version.V_8_1_0)) {
out.writeBoolean(false); // optional & unused node field
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,10 @@ public void testConnectTransportException() throws IOException {
DiscoveryNode node = new DiscoveryNode("thenode", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
ConnectTransportException ex = serialize(new ConnectTransportException(node, "msg", "action", null));
assertEquals("[][" + transportAddress + "][action] msg", ex.getMessage());
assertEquals(node, ex.node());
assertNull(ex.getCause());

ex = serialize(new ConnectTransportException(node, "msg", "action", new NullPointerException()));
assertEquals("[][" + transportAddress + "][action] msg", ex.getMessage());
assertEquals(node, ex.node());
assertTrue(ex.getCause() instanceof NullPointerException);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static org.elasticsearch.transport.TransportService.NOOP_TRANSPORT_INTERCEPTOR;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -1721,15 +1722,15 @@ public void handleResponse(StringMessageResponse response) {
public void handleException(TransportException exp) {
Throwable cause = ExceptionsHelper.unwrapCause(exp);
assertThat(cause, instanceOf(ConnectTransportException.class));
assertThat(((ConnectTransportException) cause).node(), equalTo(nodeA));
assertThat(cause.getMessage(), allOf(containsString(nodeA.getName()), containsString(nodeA.getAddress().toString())));
}
}
);

final ExecutionException e = expectThrows(ExecutionException.class, res::get);
Throwable cause = ExceptionsHelper.unwrapCause(e.getCause());
assertThat(cause, instanceOf(ConnectTransportException.class));
assertThat(((ConnectTransportException) cause).node(), equalTo(nodeA));
assertThat(cause.getMessage(), allOf(containsString(nodeA.getName()), containsString(nodeA.getAddress().toString())));

// wait for the transport to process the sending failure and disconnect from node
assertBusy(() -> assertFalse(serviceB.nodeConnected(nodeA)));
Expand Down