diff --git a/src/test/java/com/verisign/storm/metrics/reporters/GraphiteSocketSettingsTest.java b/src/test/java/com/verisign/storm/metrics/reporters/GraphiteSocketSettingsTest.java index 4537ae9..1e2378c 100644 --- a/src/test/java/com/verisign/storm/metrics/reporters/GraphiteSocketSettingsTest.java +++ b/src/test/java/com/verisign/storm/metrics/reporters/GraphiteSocketSettingsTest.java @@ -16,15 +16,10 @@ public class GraphiteSocketSettingsTest { - private InetSocketAddress graphiteSocketAddress; private ServerSocketChannel graphiteServer; @BeforeTest public void setUp() throws IOException { - String graphiteHost = "127.0.0.1"; - int graphitePort = 2003; - - graphiteSocketAddress = new InetSocketAddress(graphiteHost, graphitePort); graphiteServer = ServerSocketChannel.open(); } @@ -38,8 +33,9 @@ public void tearDown() throws Exception { @Test public void testConnectTimeout() throws IOException { + String graphiteHost = "127.0.0.1"; // Backlog of one socket - graphiteServer.socket().bind(graphiteSocketAddress, 1); + graphiteServer.socket().bind(new InetSocketAddress(graphiteHost, 0), 1); graphiteServer.configureBlocking(false); graphiteServer.accept(); @@ -49,8 +45,8 @@ public void testConnectTimeout() throws IOException { HashMap reporterConfig = new HashMap(); - reporterConfig.put(GraphiteReporter.GRAPHITE_HOST_OPTION, graphiteSocketAddress.getHostName()); - reporterConfig.put(GraphiteReporter.GRAPHITE_PORT_OPTION, String.valueOf(graphiteSocketAddress.getPort())); + reporterConfig.put(GraphiteReporter.GRAPHITE_HOST_OPTION, graphiteHost); + reporterConfig.put(GraphiteReporter.GRAPHITE_PORT_OPTION, String.valueOf(graphiteServer.socket().getLocalPort())); reporterConfig.put(GraphiteReporter.GRAPHITE_CONNECT_TIMEOUT, 1); GraphiteReporter graphiteReporter = new GraphiteReporter();