From 705465890b9d444d12f6d568e1d0bdf38699f878 Mon Sep 17 00:00:00 2001 From: Kevin Conaway Date: Mon, 18 Apr 2016 20:08:09 -0400 Subject: [PATCH] #26 Update test to use random bind port --- .../reporters/GraphiteSocketSettingsTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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();