Skip to content
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
31 changes: 31 additions & 0 deletions server/src/main/java/io/druid/server/DruidNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,35 @@ public String toString()
", port=" + port +
'}';
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

DruidNode node = (DruidNode) o;

if (port != node.port) {
return false;
}
if (!serviceName.equals(node.serviceName)) {
return false;
}
return host.equals(node.host);

}

@Override
public int hashCode()
{
int result = serviceName.hashCode();
result = 31 * result + host.hashCode();
result = 31 * result + port;
return result;
}
}
26 changes: 26 additions & 0 deletions server/src/test/java/io/druid/server/DruidNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,30 @@ public void testConflictingPortsNonsense() throws Exception
{
new DruidNode("test/service", "[2001:db8:85a3::8a2e:370:7334]:123", 456);
}

@Test
public void testEquals() throws Exception
{
final String serviceName = "serviceName";
final String host = "some.host";
final int port = 9898;
Assert.assertEquals(new DruidNode(serviceName, host, port), new DruidNode(serviceName, host, port));
Assert.assertNotEquals(new DruidNode(serviceName, host, port), new DruidNode(serviceName, host, -1));
Assert.assertNotEquals(new DruidNode(serviceName, host, port), new DruidNode(serviceName, "other.host", port));
Assert.assertNotEquals(new DruidNode(serviceName, host, port), new DruidNode("otherServiceName", host, port));
}

@Test
public void testHashCode() throws Exception
{

final String serviceName = "serviceName";
final String host = "some.host";
final int port = 9898;
Assert.assertEquals(new DruidNode(serviceName, host, port).hashCode(), new DruidNode(serviceName, host, port).hashCode());
// Potential hash collision if hashCode method ever changes
Assert.assertNotEquals(new DruidNode(serviceName, host, port).hashCode(), new DruidNode(serviceName, host, -1).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, port).hashCode(), new DruidNode(serviceName, "other.host", port).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, port).hashCode(), new DruidNode("otherServiceName", host, port).hashCode());
}
}