Skip to content
Closed
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 @@ -132,6 +132,27 @@ protected Setting<Boolean> roleSetting() {
return Setting.boolSetting("node. " + roleName(), false, Setting.Property.NodeScope);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UnknownRole that = (UnknownRole) o;
return Objects.equals(roleName(), that.roleName()) &&
Objects.equals(roleNameAbbreviation(), that.roleNameAbbreviation());
}

@Override
public int hashCode() {
return Objects.hash(roleName(), roleNameAbbreviation());
}

@Override
public String toString() {
return "UnknownRole{" +
"roleName='" + roleName() + '\'' +
", roleAbbreviation='" + roleNameAbbreviation() + '\'' +
'}';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these can all go in the base class, as final, with adding getClass() to the toString implementation?

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.EqualsHashCodeTestUtils;

import java.util.Set;

Expand Down Expand Up @@ -75,4 +76,15 @@ protected Setting<Boolean> roleSetting() {
assertThat(e, hasToString(containsString("Duplicate key")));
}

public void testUnknownDiscoveryNodeRoleEqualsHashCode() {
EqualsHashCodeTestUtils.checkEqualsAndHashCode(new DiscoveryNodeRole.UnknownRole(randomAlphaOfLength(10), randomAlphaOfLength(1)),
r -> new DiscoveryNodeRole.UnknownRole(r.roleName(), r.roleNameAbbreviation()),
r -> {
if (randomBoolean()) {
return new DiscoveryNodeRole.UnknownRole(randomAlphaOfLength(21 - r.roleName().length()), r.roleNameAbbreviation());
} else {
return new DiscoveryNodeRole.UnknownRole(r.roleName(), randomAlphaOfLength(3 - r.roleNameAbbreviation().length()));
}
});
}
}