fix port not set in DruidNode

This commit is contained in:
Xavier Léauté 2014-12-01 14:37:28 -08:00
parent 8b3652a67a
commit 59542c41f8
4 changed files with 13 additions and 3 deletions

View File

@ -93,7 +93,7 @@ public class HadoopDruidIndexerConfig
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("hadoop-indexer", "localhost", 0)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("hadoop-indexer", null, null)
);
}
}

View File

@ -131,8 +131,12 @@ public class DruidNode
* Returns host and port together as something that can be used as part of a URI.
*/
public String getHostAndPort() {
if(port < 0) {
return HostAndPort.fromString(host).toString();
} else {
return HostAndPort.fromParts(host, port).toString();
}
}
@Override
public String toString()

View File

@ -109,7 +109,7 @@ public class InitializationTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", "localhost", 0)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null)
);
}
}

View File

@ -34,6 +34,12 @@ public class DruidNodeTest
node = new DruidNode(service, null, null);
Assert.assertEquals(DruidNode.DEFAULT_HOST, node.getHost());
Assert.assertEquals(-1, node.getPort());
Assert.assertEquals("localhost", node.getHostAndPort());
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", -1);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertEquals(-1, node.getPort());
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]", node.getHostAndPort());
node = new DruidNode(service, "abc:123", null);
Assert.assertEquals("abc", node.getHost());