From 59542c41f82497cff5fd3ce33add159f62520630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Mon, 1 Dec 2014 14:37:28 -0800 Subject: [PATCH] fix port not set in DruidNode --- .../java/io/druid/indexer/HadoopDruidIndexerConfig.java | 2 +- server/src/main/java/io/druid/server/DruidNode.java | 6 +++++- .../java/io/druid/initialization/InitializationTest.java | 2 +- server/src/test/java/io/druid/server/DruidNodeTest.java | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/indexing-hadoop/src/main/java/io/druid/indexer/HadoopDruidIndexerConfig.java b/indexing-hadoop/src/main/java/io/druid/indexer/HadoopDruidIndexerConfig.java index 17e4ebcddcf..e33a9c30fb5 100644 --- a/indexing-hadoop/src/main/java/io/druid/indexer/HadoopDruidIndexerConfig.java +++ b/indexing-hadoop/src/main/java/io/druid/indexer/HadoopDruidIndexerConfig.java @@ -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) ); } } diff --git a/server/src/main/java/io/druid/server/DruidNode.java b/server/src/main/java/io/druid/server/DruidNode.java index 363a5614df4..eef71a40886 100644 --- a/server/src/main/java/io/druid/server/DruidNode.java +++ b/server/src/main/java/io/druid/server/DruidNode.java @@ -131,7 +131,11 @@ public class DruidNode * Returns host and port together as something that can be used as part of a URI. */ public String getHostAndPort() { - return HostAndPort.fromParts(host, port).toString(); + if(port < 0) { + return HostAndPort.fromString(host).toString(); + } else { + return HostAndPort.fromParts(host, port).toString(); + } } @Override diff --git a/server/src/test/java/io/druid/initialization/InitializationTest.java b/server/src/test/java/io/druid/initialization/InitializationTest.java index 22953708cdd..2dce7260796 100644 --- a/server/src/test/java/io/druid/initialization/InitializationTest.java +++ b/server/src/test/java/io/druid/initialization/InitializationTest.java @@ -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) ); } } diff --git a/server/src/test/java/io/druid/server/DruidNodeTest.java b/server/src/test/java/io/druid/server/DruidNodeTest.java index 96721dece00..4679c480c11 100644 --- a/server/src/test/java/io/druid/server/DruidNodeTest.java +++ b/server/src/test/java/io/druid/server/DruidNodeTest.java @@ -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());