flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpe...@apache.org
Subject git commit: FLUME-2026. TestHTTPSource should use any available port rather than a hardcoded port number.
Date Sun, 23 Jun 2013 11:10:28 GMT
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 <mpercy@apache.org>
Authored: Sun Jun 23 04:08:46 2013 -0700
Committer: Mike Percy <mpercy@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


Mime
View raw message