You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flume.apache.org by mp...@apache.org on 2013/06/23 13:10:28 UTC

git commit: FLUME-2026. TestHTTPSource should use any available port rather than a hardcoded port number.

Updated Branches:
  refs/heads/trunk 171310fb1 -> 15f280f75


FLUME-2026. TestHTTPSource should use any available port rather than a hardcoded port number.

(Hari Shreedharan, Mike Percy via Mike Percy)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/15f280f7
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/15f280f7
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/15f280f7

Branch: refs/heads/trunk
Commit: 15f280f75135f69778f04557ed67e230dea7e2bd
Parents: 171310f
Author: Mike Percy <mp...@apache.org>
Authored: Sun Jun 23 04:08:46 2013 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Sun Jun 23 04:08:46 2013 -0700

----------------------------------------------------------------------
 .../apache/flume/source/http/TestHTTPSource.java    | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/15f280f7/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
index 59d1cb1..8952db3 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
@@ -44,6 +44,7 @@ import org.junit.Test;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.lang.reflect.Type;
+import java.net.ServerSocket;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -58,12 +59,21 @@ public class TestHTTPSource {
 
   private static HTTPSource source;
   private static Channel channel;
-  private int selectedPort;
+  private static int selectedPort;
   DefaultHttpClient httpClient;
   HttpPost postRequest;
 
+  private static int findFreePort() throws IOException {
+    ServerSocket socket = new ServerSocket(0);
+    int port = socket.getLocalPort();
+    socket.close();
+    return port;
+  }
+
   @BeforeClass
   public static void setUpClass() throws Exception {
+    selectedPort = findFreePort();
+
     source = new HTTPSource();
     channel = new MemoryChannel();
 
@@ -82,7 +92,7 @@ public class TestHTTPSource {
     channel.start();
     Context context = new Context();
 
-    context.put("port", String.valueOf(41404));
+    context.put("port", String.valueOf(selectedPort));
     context.put("host", "0.0.0.0");
 
     Configurables.configure(source, context);
@@ -98,7 +108,7 @@ public class TestHTTPSource {
   @Before
   public void setUp() {
     httpClient = new DefaultHttpClient();
-    postRequest = new HttpPost("http://0.0.0.0:41404");
+    postRequest = new HttpPost("http://0.0.0.0:" + selectedPort);
   }
 
   @Test