Skip to content

Commit

Permalink
Remove unused ConnectTransportException#node (#80944)
Browse files Browse the repository at this point in the history
`ConnectTransportException#node` is only used in a couple of assertions
in tests, but those assertions are either unnecessary or can be
rewritten without it so this field is effectively unused. This commit
removes it.
  • Loading branch information
DaveCTurner authored Nov 23, 2021
1 parent 2e8a973 commit 49feb65
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
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

0 comments on commit 49feb65

Please sign in to comment.